Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

refactor: begin tearing apart AutopushSettings #933

Merged
merged 1 commit into from
Jun 23, 2017
Merged

Conversation

pjenvey
Copy link
Member

@pjenvey pjenvey commented Jun 23, 2017

  • move db concerns (incl. metrics) into a simple DatabaseManager.
    heavier db init's moved into its own setup() method that most tests
    don't even call
  • split out routers, now connection doesn't even create them
  • kill PushState.msg_limit, nor did it need a metrics attrib

issue #632

@codecov-io
Copy link

codecov-io commented Jun 23, 2017

Codecov Report

Merging #933 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #933   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          57     57           
  Lines        9464   9538   +74     
=====================================
+ Hits         9464   9538   +74
Impacted Files Coverage Δ
autopush/router/webpush.py 100% <ø> (ø) ⬆️
autopush/web/health.py 100% <ø> (ø) ⬆️
autopush/tests/test_endpoint.py 100% <100%> (ø) ⬆️
autopush/web/registration.py 100% <100%> (ø) ⬆️
autopush/websocket.py 100% <100%> (ø) ⬆️
autopush/router/gcm.py 100% <100%> (ø) ⬆️
autopush/router/apnsrouter.py 100% <100%> (ø) ⬆️
autopush/tests/test_router.py 100% <100%> (ø) ⬆️
autopush/tests/test_main.py 100% <100%> (ø) ⬆️
autopush/router/fcm.py 100% <100%> (ø) ⬆️
... and 22 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75a1fa0...fc66ddc. Read the comment docs.

autopush/db.py Outdated
def _tomorrow(self):
return datetime.date.today() + datetime.timedelta(days=1)

def create_initial_message_tables(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come some of these methods have type annotations, but not all of them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot some of these and we do have some circular imports. this is going to start getting typing.TYPE_CHECKING ugly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok.

today = datetime.date.today()
last_month = get_rotating_message_table(self._message_prefix, -1)
this_month = get_rotating_message_table(self._message_prefix)
self.current_month = today.month
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the movement of this code from where it was before, so if a later refactor has this coming that's fine. I assume at some point all initialization stuff like this will occur once (in a single method, so multiple methods aren't setting initial states on self).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly what I'm trying to get at -- I actually did forget that Router/Storage are still being initialized upon creation here. I'll fix this later in another commit. DatabaseManager() creation should be light weight (no network/db calls), until you explicitly tell it to initialize

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@@ -97,3 +97,17 @@ def gauge(self, name, count, **kwargs):
def timing(self, name, duration, **kwargs):
self._client.timing(self._prefix_name(name), value=duration,
host=self._host, **kwargs)


def from_settings(settings):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type signature or doc string?

"""Create a dict of IRouters for the given settings"""
router_conf = settings.router_conf
routers = dict(
simplepush=SimpleRouter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it possible to not enable simplepush?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but not right now

bbangert
bbangert previously approved these changes Jun 23, 2017
- move db concerns (incl. metrics) into a simple DatabaseManager.
heavier db init's moved into its own setup() method that most tests
don't even call
- split out routers, now connection doesn't even create them
- kill PushState.msg_limit, nor did it need a metrics attrib

issue #632
_message_prefix = attrib(default="message") # type: str

@classmethod
def from_settings(cls, settings):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not an init?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we get a light weight __init__ automatically w/ @attrs (some tests use it). these might change around a bit though in a later commit, re the deferred initialization comments above

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! ok, kinda like how we have to have ap_settings.


import cyclone.web
from twisted.logger import Logger
from twisted.python import failure

if TYPE_CHECKING: # pragma: nocover
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet

@jrconlin jrconlin merged commit 465551d into master Jun 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants