Skip to content

Commit

Permalink
Merge pull request revsys#11 from stefanfoulis/feature/celery3-support
Browse files Browse the repository at this point in the history
adds support for celery3
  • Loading branch information
KristianOellegaard committed Oct 20, 2014
2 parents b027211 + 85659ef commit a062d9c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ Add required apps:
'health_check_cache',
'health_check_storage',
```
(remember to add dependencies, e.g. djcelery - however you should have that already, if you have celery running)
(remember to add dependencies, e.g. djcelery - however you should have that already, if you have celery running).
You'll also have to make sure that you have a
`result backend <http://celery.readthedocs.org/en/latest/configuration.html?highlight=result_backend#std:setting-CELERY_RESULT_BACKEND>`_
configured.
If you are using celery 3, use ``health_check_celery3`` instead of ``health_check_celery``.


Set up monitoring
=================
Expand Down
Empty file.
Empty file added health_check_celery3/models.py
Empty file.
23 changes: 23 additions & 0 deletions health_check_celery3/plugin_health_check.py
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)
7 changes: 7 additions & 0 deletions health_check_celery3/tasks.py
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

0 comments on commit a062d9c

Please sign in to comment.