def send_task(name, args=None, kwargs=None, **opts):
"""
Send a task by name. Contrary to app.send_task, this function respects the
CELERY_ALWAYS_EAGER settings, which is necessary in tests. As a
consequence, it works only for registered tasks.
"""
if settings.CELERY_ALWAYS_EAGER:
task = app.tasks[name] # Raises a NotRegistered exception for unregistered tasks
return task.apply(args=args, kwargs=kwargs, **opts)
else:
return app.send_task(name, args=args, kwargs=kwargs)
评论列表
文章目录