Skip to content

Commit

Permalink
close db connection before entering sleep mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjiang committed Dec 13, 2024
1 parent 2ff9c9f commit e82687c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ezidapp/management/commands/proc-expunge.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def get_id_range_by_time(self, time_range: Q):
last_id = last_record.id
except Exception as ex:
log.error(f"Database error while retrieving first and last record from Identifier: {ex}")
# add retry logic here

return first_id, last_id

Expand Down Expand Up @@ -229,7 +230,10 @@ def seconds_to_date(self, seconds_since_epoch: int) -> str:

def sleep_and_prepare_next_batch(self):
sleep_time = django.conf.settings.DAEMONS_LONG_SLEEP
django.db.connections["default"].close()
log.info(f'Closing DB connections before entering sleep mode.')
log.info(f"Sleep {sleep_time} sec before running next batch.")

self.sleep(sleep_time)
self.min_age_ts = self.max_age_ts
self.max_age_ts = int(time.time()) - django.conf.settings.DAEMONS_EXPUNGE_MAX_AGE_SEC
Expand Down

0 comments on commit e82687c

Please sign in to comment.