Skip to content

Commit f268442

Browse files
authored
Merge pull request #54 from cuda-networks/fix-health-check
Fix the healthcheck
2 parents e9e3295 + 3ef04ec commit f268442

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

eb_sqs/worker/service.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class WorkerService(object):
2929

3030
def process_queues(self, queue_names):
3131
# type: (list) -> None
32+
self.write_healthcheck_file()
33+
self.last_healthcheck_time = timezone.now()
34+
3235
logger.debug('[django-eb-sqs] Connecting to SQS: {}'.format(', '.join(queue_names)))
3336

3437
sqs = boto3.resource(
@@ -44,9 +47,6 @@ def process_queues(self, queue_names):
4447
static_queues = queues
4548
last_update_time = timezone.now() - timedelta(seconds=settings.REFRESH_PREFIX_QUEUES_S)
4649

47-
self.write_healthcheck_file()
48-
last_healthcheck_time = timezone.now()
49-
5050
logger.debug('[django-eb-sqs] Connected to SQS: {}'.format(', '.join(queue_names)))
5151

5252
worker = WorkerFactory.default().create()
@@ -75,12 +75,9 @@ def process_queues(self, queue_names):
7575
else:
7676
self.process_messages(queues, worker, static_queues)
7777

78-
if timezone.now() - timedelta(seconds=settings.MIN_HEALTHCHECK_WRITE_PERIOD_S) > last_healthcheck_time:
79-
self.write_healthcheck_file()
80-
last_healthcheck_time = timezone.now()
81-
8278
def process_messages(self, queues, worker, static_queues):
8379
# type: (list, Worker, list) -> None
80+
8481
for queue in queues:
8582
try:
8683
messages = self.poll_messages(queue)
@@ -101,6 +98,10 @@ def process_messages(self, queues, worker, static_queues):
10198
self.delete_messages(queue, msg_entries)
10299

103100
self._send_signal(MESSAGES_DELETED, messages=messages)
101+
102+
if timezone.now() - timedelta(seconds=settings.MIN_HEALTHCHECK_WRITE_PERIOD_S) > self.last_healthcheck_time:
103+
self.write_healthcheck_file()
104+
self.last_healthcheck_time = timezone.now()
104105
except ClientError as exc:
105106
error_code = exc.response.get('Error', {}).get('Code', None)
106107
if error_code == 'AWS.SimpleQueueService.NonExistentQueue' and queue not in static_queues:

0 commit comments

Comments
 (0)