Skip to content

Commit

Permalink
take a long sleep if query returns no IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjiang committed Nov 7, 2024
1 parent 2e961a6 commit 5f84c7e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions ezidapp/management/commands/proc-expunge_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ def run(self):
if filter_by_id is not None:
combined_filter &= filter_by_id
else:
combined_filter &= time_range
sleep_time = django.conf.settings.DAEMONS_LONG_SLEEP
log.info(f"Sleep {sleep_time} sec before running next batch.")
self.sleep(sleep_time)
min_age_ts = max_age_ts
max_age_ts = int(time.time()) - django.conf.settings.DAEMONS_EXPUNGE_MAX_AGE_SEC
time_range = Q(createTime__gte=min_age_ts) & Q(createTime__lte=max_age_ts)
min_id, max_id = self.get_id_range_by_time(time_range)
continue

qs = (
ezidapp.models.identifier.Identifier.objects.filter(combined_filter)
Expand Down Expand Up @@ -175,8 +182,7 @@ def get_id_range_by_time(self, time_range: Q):
last_id = last_record.id

return first_id, last_id



def date_to_seconds(self, date_time_str: str) -> int:
"""
Convert date/time string to seconds since the Epotch.
Expand Down

0 comments on commit 5f84c7e

Please sign in to comment.