Skip to content

Refactor event sync to pass account into constructors#459

Open
squeaky-pl wants to merge 3 commits into
masterfrom
refactor-event-sync
Open

Refactor event sync to pass account into constructors#459
squeaky-pl wants to merge 3 commits into
masterfrom
refactor-event-sync

Conversation

@squeaky-pl
Copy link
Copy Markdown
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
Copy Markdown
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! 👌

Comment thread inbox/events/abstract.py
The token
"""
with session_scope(self.namespace_id) as db_session:
acc = db_session.query(Account).get(self.account_id)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Typo: received

Comment thread tests/events/test_sync.py
namespace_id,
provider_class=GoogleEventsProvider,
)
event_sync = EventSync(generic_account, provider_class=GoogleEventsProvider,)
Copy link
Copy Markdown
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.

2 participants