Skip to content
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

Refactor event sync to pass account into constructors #459

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

squeaky-pl
Copy link
Contributor

@squeaky-pl squeaky-pl commented Dec 23, 2022

This is a follow-up on #458,

This refactors Google and Microsoft event sync to accept Account objects in constructor and not in methods, as each of EventSync/WebhookEventSync greenlet and EventsProvider work always on a single account.

@squeaky-pl squeaky-pl changed the title Refactor events sync to pass account into constructors Refactor event sync to pass account into constructors Dec 23, 2022
Copy link
Member

@wojcikstefan wojcikstefan left a comment

Choose a reason for hiding this comment

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

Looks nice and clean! 👌

@@ -102,13 +95,9 @@ def _get_access_token(
Returns:
The token
"""
with session_scope(self.namespace_id) as db_session:
acc = db_session.query(Account).get(self.account_id)
Copy link
Member

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?

Comment on lines 55 to 65
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",
)
Copy link
Member

Choose a reason for hiding this comment

The 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 * to force all of them to be passed as kwargs. That way at least it's a bit clearer what the role/expectation is for each variable. For example, I think provider_name=account.verbose_provider is clearer than just passing account.verbose_provider into this constructor.

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
Copy link
Member

Choose a reason for hiding this comment

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

Typo: received

namespace_id,
provider_class=GoogleEventsProvider,
)
event_sync = EventSync(generic_account, provider_class=GoogleEventsProvider,)
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Probably don't need that trailing comma.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants