diff --git a/drinks_touch/database/models/account.py b/drinks_touch/database/models/account.py index 0c684e73..4a40d919 100644 --- a/drinks_touch/database/models/account.py +++ b/drinks_touch/database/models/account.py @@ -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 @@ -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? diff --git a/drinks_touch/tasks/sync_from_ldap.py b/drinks_touch/tasks/sync_from_ldap.py index 566c28fd..04c8ea37 100644 --- a/drinks_touch/tasks/sync_from_ldap.py +++ b/drinks_touch/tasks/sync_from_ldap.py @@ -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 + )