Django-celery project, how to handle results from result-backend? -
1) working on web application exposes rest api , uses django , celery handle request , solve them. request in order solved, there have submitted set of celery tasks amqp queue, executed on workers (situated on other machines). each task cpu intensive , takes long (hours) finish.
i have configured celery utilize amqp results-backend, , using rabbitmq celery's broker.
each task returns result needs stored afterwards in db, not workers directly. "central node" - machine running django-celery , publishing tasks in rabbitmq queue - has access storage db, results workers have homecoming somehow on machine.
the question how can process results of tasks execution afterwards? after worker finishes, result gets stored in configured results-backend (amqp), don't know best way results there , process them.
all find in documentation can either check on results's status time time with:
result.state
which means need dedicated piece of code runs periodically command, , hence keeps busy whole thread/process this, or block with:
result.get()
until task finishes, not wish.
the solution can think of have on "central node" thread runs periodically function checks on async_results returned each task @ submission, , take action if task has finished status.
does have other suggestion?
also, since backend-results' processing takes place on "central node", aim minimize impact of operation on machine.
what best way that?
2) how people solve problem of dealing results returned workers , set in backend-results? (assuming backend-results has been configured)
i'm not sure if understand question, take business relationship each task has task id. if tasks beingness sent users can store ids , check results using json follows:
#urls.py djcelery.views import is_task_successful urlpatterns += patterns('', url(r'(?p<task_id>[\w\d\-\.]+)/done/?$', is_task_successful, name='celery-is_task_successful'), )
other related concept of signals each finished task emits signal. finnished task emit task_success signal. more can found on real time proc.
django celery
No comments:
Post a Comment