DBuildService / dbs-server

BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

do not fork new thread for callback #4

Open misli opened 9 years ago

misli commented 9 years ago

If we really need to use callback at all (i believe we do not), use string definition of callback ('module.submodule.func') and pass it to task. In the task use django.utils.module_loading.import_string to get the actual callback function.

twaugh commented 9 years ago

Another possible approach is to use celery signals:

@signals.task_postrun(sender=dbs.tasks.build_image)
def task_postrun_handler(sender, **kwargs):
    ...

If I'm reading it right, task_postrun_handler() would be run in the server not the worker. http://celery.readthedocs.org/en/latest/userguide/signals.html

TomasTomecek commented 9 years ago

I've implemented state change in DB via signals: https://github.com/DBuildService/dbs-server/commit/ef6bc60152ac9d7b8687a1d2db752b12462c14ba#diff-993fb812f6bae891a1e5603a70d7a96bR31

IMO, this could really be the easiest and most flexible solution. Good job scouting that out, Tim.