Skip to content

Commit

Permalink
Make ldap task interruptable
Browse files Browse the repository at this point in the history
  • Loading branch information
soerface committed Oct 27, 2024
1 parent 9260f43 commit 2dc51d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion drinks_touch/database/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Account(Base):
summary_email_notification_setting = Column(String(50), unique=False)

@staticmethod
def sync_all_from_ldap(progress=None):
def sync_all_from_ldap(progress=None, was_killed=None):
if progress is None:
progress = lambda *args, **kwargs: None # noqa: E731

Expand All @@ -43,6 +43,8 @@ def sync_all_from_ldap(progress=None):
# Not really necessary, but it's nice to keep history.
ldap_users = sorted(ldap_users, key=lambda x: x["id"] or math.inf)
for i, user in enumerate(ldap_users):
if was_killed is not None and was_killed():
raise Exception("Task was killed")
progress(i / len(ldap_users))
if user["id"] == 10000 and user["name"] == "malled2":
# malled how did you manage to get two accounts with the same id?
Expand Down
4 changes: 3 additions & 1 deletion drinks_touch/tasks/sync_from_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ def set_progress(progress):
self.progress = 0

with Session.begin():
Account.sync_all_from_ldap(progress=set_progress)
Account.sync_all_from_ldap(
progress=set_progress, was_killed=lambda: self.sig_killed
)

0 comments on commit 2dc51d1

Please sign in to comment.