vendredi 2 octobre 2015

Celery task check application environment before run

In my application I have celery task that make subprocess call to external bin (may be not installed).

My task acts as follow:

class MyTask(app.Task):

    def __init__(self):
       try:
           do_some_check_on_the_ext_bin()
       except (subprocess.CalledProcessError, subprocess.TimeoutExpired):
            raise EnvironmentError
    def run(self, **kw):
       do_the_job_and_call_the_bin()

But I wonder if it the best way to do, to put the environment check in the init method ?

Aucun commentaire:

Enregistrer un commentaire