Exemplo n.º 1
0
        def apply_async(self, args=None, kwargs=None, **c_kwargs):
            """
            @param args: Tuple of arguments to be passed to function
            @param kwargs: Dict of arguments to be passed to function
            @param **c_kwargs: Dict of arguments to be passed to celery (e.g. countdown)
            @return: Job
            """

            with transaction.commit_on_success():
                # Create the Job synchronously so it immediately appears in the admin site.
                # Do this in a transaction to guarantee that it's committed in the db
                # before it's used in a celery thread.
                job = Job.create_with_fn_name(function)

                # Pass the location and name of the function, so that when the task runs
                # it imports the latest version of that function's code.
                extra_info = (function.__module__, function.__name__, job.id)
                args = extra_info + (args or ())
                kwargs = kwargs or {}
                c_kwargs = c_kwargs or {}

            async_result = boomerang_task.apply_async(args=args, kwargs=kwargs, **c_kwargs)
            job.set_celery_task_id(async_result.id)
            return job