-
Notifications
You must be signed in to change notification settings - Fork 13
Refactor event sync to pass account into constructors #459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,27 +40,26 @@ class EventSync(BaseSyncMonitor): | |
|
|
||
| def __init__( | ||
| self, | ||
| email_address: str, | ||
| provider_name: str, | ||
| account_id: int, | ||
| namespace_id: int, | ||
| account: Account, | ||
| provider_class: Type[AbstractEventsProvider], | ||
| poll_frequency: int = POLL_FREQUENCY, | ||
| ): | ||
| bind_context(self, "eventsync", account_id) | ||
| self.provider = provider_class(account_id, namespace_id) | ||
| bind_context(self, "eventsync", account.id) | ||
| self.provider = provider_class(account) | ||
| self.log = logger.new( | ||
| account_id=account_id, component="calendar sync", provider=provider_name | ||
| account_id=account.id, | ||
| component="calendar sync", | ||
| provider=account.verbose_provider, | ||
| ) | ||
|
|
||
| BaseSyncMonitor.__init__( | ||
| self, | ||
| account_id, | ||
| namespace_id, | ||
| email_address, | ||
| account.id, | ||
| account.namespace.id, | ||
| account.email_address, | ||
| EVENT_SYNC_FOLDER_ID, | ||
| EVENT_SYNC_FOLDER_NAME, | ||
| provider_name, | ||
| account.verbose_provider, | ||
| poll_frequency=poll_frequency, | ||
| scope="calendar", | ||
| ) | ||
|
Comment on lines
55
to
65
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a side note and not something that needs to happen in this PR, but I feel like this number of arguments could warrant using |
||
|
|
@@ -239,19 +238,16 @@ def handle_event_updates( | |
|
|
||
|
|
||
| class WebhookEventSync(EventSync): | ||
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
| with session_scope(self.namespace_id) as db_session: | ||
| account = db_session.query(Account).get(self.account_id) | ||
| if ( | ||
| self.provider.webhook_notifications_enabled(account) | ||
| and kwargs.get("poll_frequency") is None | ||
| ): | ||
| # Run the sync loop more frequently if push notifications are | ||
| # enabled. Note that we'll only update the calendar if a | ||
| # Webhook was receicved recently, or if we haven't synced for | ||
| # too long. | ||
| self.poll_frequency = PUSH_NOTIFICATION_POLL_FREQUENCY | ||
| def __init__( | ||
| self, account: Account, provider_class: Type[AbstractEventsProvider], | ||
| ): | ||
| super().__init__(account, provider_class) | ||
| if self.provider.webhook_notifications_enabled(): | ||
| # Run the sync loop more frequently if push notifications are | ||
| # enabled. Note that we'll only update the calendar if a | ||
| # Webhook was receicved recently, or if we haven't synced for | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: received |
||
| # too long. | ||
| self.poll_frequency = PUSH_NOTIFICATION_POLL_FREQUENCY | ||
|
|
||
| def sync(self) -> None: | ||
| """Query a remote provider for updates and persist them to the | ||
|
|
@@ -295,12 +291,12 @@ def _refresh_webhook_subscriptions(self) -> None: | |
| with session_scope(self.namespace_id) as db_session: | ||
| account = db_session.query(Account).get(self.account_id) | ||
|
|
||
| if not self.provider.webhook_notifications_enabled(account): | ||
| if not self.provider.webhook_notifications_enabled(): | ||
| self.log.warning("Webhook notifications disabled") | ||
| return | ||
|
|
||
| if account.needs_new_calendar_list_watch(): | ||
| calendar_list_expiration = self.provider.watch_calendar_list(account) | ||
| calendar_list_expiration = self.provider.watch_calendar_list() | ||
| if calendar_list_expiration is not None: | ||
| account.new_calendar_list_watch(calendar_list_expiration) | ||
|
|
||
|
|
@@ -311,9 +307,7 @@ def _refresh_webhook_subscriptions(self) -> None: | |
| ) | ||
| for calendar in calendars_to_watch: | ||
| try: | ||
| event_list_expiration = self.provider.watch_calendar( | ||
| account, calendar | ||
| ) | ||
| event_list_expiration = self.provider.watch_calendar(calendar) | ||
| if event_list_expiration is not None: | ||
| calendar.new_event_watch(event_list_expiration) | ||
| except CalendarGoneException: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any possible reason why reloading the account information here might've been important? Or is the freshest possible state of the account a) irrelevant, or b) already ensured through different logic somehow?