本文整理匯總了Python中celery.task.periodic_task方法的典型用法代碼示例。如果您正苦於以下問題:Python task.periodic_task方法的具體用法?Python task.periodic_task怎麽用?Python task.periodic_task使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類celery.task
的用法示例。
在下文中一共展示了task.periodic_task方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: periodic_task
# 需要導入模塊: from celery import task [as 別名]
# 或者: from celery.task import periodic_task [as 別名]
def periodic_task(*d_args, **d_kwargs):
# behaves like @periodic_task, but emails about exceptions.
def real_decorator(f):
@celery_periodic_task(*d_args, **d_kwargs)
@wraps(f)
def wrapper(*f_args, **f_kwargs):
# try the task; email any exceptions we get
try:
res = f(*f_args, **f_kwargs)
except Exception as e:
# email admins and re-raise
exc_type, exc_value, exc_traceback = sys.exc_info()
subject = 'task failure in %s.%s' % (f.__module__, f.__name__)
msg = 'The periodic task %s.%s failed:\n\n%s' % (f.__module__, f.__name__,
'\n'.join(traceback.format_exception(exc_type, exc_value, exc_traceback)))
mail_admins(subject=subject, message=msg, fail_silently=True)
raise
return res
return wrapper
return real_decorator