forked from revsys/django-health-check
-
Notifications
You must be signed in to change notification settings - Fork 0
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 revsys#11 from stefanfoulis/feature/celery3-support
adds support for celery3
- Loading branch information
Showing
5 changed files
with
36 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
Empty file.
Empty file.
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,23 @@ | ||
from health_check.plugins import plugin_dir | ||
from health_check.backends.base import BaseHealthCheckBackend, ServiceUnavailable | ||
from health_check_celery3.tasks import add | ||
from datetime import datetime, timedelta | ||
from time import sleep | ||
|
||
|
||
class CeleryHealthCheck(BaseHealthCheckBackend): | ||
|
||
def check_status(self): | ||
try: | ||
result = add.apply_async(args=[4, 4], expires=datetime.now() + timedelta(seconds=3), connect_timeout=3) | ||
now = datetime.now() | ||
while (now + timedelta(seconds=3)) > datetime.now(): | ||
print " checking...." | ||
if result.result == 8: | ||
return True | ||
sleep(0.5) | ||
except IOError: | ||
pass | ||
raise ServiceUnavailable("Unknown error") | ||
|
||
plugin_dir.register(CeleryHealthCheck) |
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,7 @@ | ||
from __future__ import absolute_import | ||
from celery import shared_task | ||
|
||
|
||
@shared_task | ||
def add(x, y): | ||
return x + y |