Skip to content

Commit 310d6be

Browse files
authored
Merge pull request #1466 from mozilla-services/fix/SYNC-3638
fix: connect to the db once instead of every loop iteration
2 parents ecb2902 + 670d683 commit 310d6be

File tree

3 files changed

+163
-38
lines changed

3 files changed

+163
-38
lines changed

Cargo.lock

Lines changed: 138 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/tokenserver/process_account_events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def process_account_events(queue_name, aws_region=None, queue_wait_time=20):
5151
to interrupt execution you'll need to e.g. SIGINT the process.
5252
"""
5353
logger.info("Processing account events from %s", queue_name)
54+
database = Database()
5455
try:
5556
# Connect to the SQS queue.
5657
# If no region is given, infer it from the instance metadata.
@@ -68,7 +69,7 @@ def process_account_events(queue_name, aws_region=None, queue_wait_time=20):
6869
msg = queue.read(wait_time_seconds=queue_wait_time)
6970
if msg is None:
7071
continue
71-
process_account_event(msg.get_body())
72+
process_account_event(database, msg.get_body())
7273
# This intentionally deletes the event even if it was some
7374
# unrecognized type. Not point leaving a backlog.
7475
queue.delete_message(msg)
@@ -77,9 +78,8 @@ def process_account_events(queue_name, aws_region=None, queue_wait_time=20):
7778
raise
7879

7980

80-
def process_account_event(body):
81+
def process_account_event(database, body):
8182
"""Parse and process a single account event."""
82-
database = Database()
8383
# Try very hard not to error out if there's junk in the queue.
8484
email = None
8585
event_type = None

0 commit comments

Comments
 (0)