本文整理汇总了Python中models.Job.create_with_fn_name方法的典型用法代码示例。如果您正苦于以下问题:Python Job.create_with_fn_name方法的具体用法?Python Job.create_with_fn_name怎么用?Python Job.create_with_fn_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Job
的用法示例。
在下文中一共展示了Job.create_with_fn_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: apply_async
# 需要导入模块: from models import Job [as 别名]
# 或者: from models.Job import create_with_fn_name [as 别名]
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