-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from cuda-networks/healthcheck
Healthcheck
- Loading branch information
Showing
4 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
|
||
import logging | ||
from datetime import timedelta | ||
|
||
from django.core.management import BaseCommand | ||
from django.utils import timezone | ||
from django.utils.dateparse import parse_datetime | ||
|
||
from eb_sqs import settings | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Checks the SQS worker is healthy, and if not returns a failure code' | ||
|
||
def add_arguments(self, parser): | ||
pass | ||
|
||
def handle(self, *args, **options): | ||
try: | ||
with open(settings.HEALTHCHECK_FILE_NAME, 'r') as file: | ||
last_healthcheck_date_str = file.readlines()[0] | ||
|
||
if parse_datetime(last_healthcheck_date_str) < timezone.now() - timedelta(seconds=settings.HEALTHCHECK_UNHEALTHY_PERIOD_S): | ||
self._return_failure() | ||
except Exception: | ||
self._return_failure() | ||
|
||
@staticmethod | ||
def _return_failure(): | ||
logger.warning('[django-eb-sqs] Health check failed') | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters