-
-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create jobs to trigger sending all alias as create events (#2126)
* Create jobs to trigger sending all alias as create events * Set events in past tense * fix test * Removed debug log * Log messages
- Loading branch information
Showing
13 changed files
with
180 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from app.events.event_dispatcher import EventDispatcher, Dispatcher | ||
from app.events.generated.event_pb2 import EventContent, AliasCreated, AliasCreatedList | ||
from app.log import LOG | ||
from app.models import User, Alias | ||
|
||
|
||
def send_alias_creation_events_for_user( | ||
user: User, dispatcher: Dispatcher, chunk_size=50 | ||
): | ||
if user.disabled: | ||
LOG.i("User {user} is disabled. Skipping sending events for that user") | ||
return | ||
chunk_size = min(chunk_size, 50) | ||
event_list = [] | ||
for alias in ( | ||
Alias.yield_per_query(chunk_size) | ||
.filter_by(user_id=user.id) | ||
.order_by(Alias.id.asc()) | ||
): | ||
event_list.append( | ||
AliasCreated( | ||
alias_id=alias.id, | ||
alias_email=alias.email, | ||
alias_note=alias.note, | ||
enabled=alias.enabled, | ||
) | ||
) | ||
if len(event_list) >= chunk_size: | ||
EventDispatcher.send_event( | ||
user, | ||
EventContent(alias_create_list=AliasCreatedList(events=event_list)), | ||
dispatcher=dispatcher, | ||
) | ||
event_list = [] | ||
if len(event_list) > 0: | ||
EventDispatcher.send_event( | ||
user, | ||
EventContent(alias_create_list=AliasCreatedList(events=event_list)), | ||
dispatcher=dispatcher, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.