本文整理汇总了Python中celery.task.task方法的典型用法代码示例。如果您正苦于以下问题:Python task.task方法的具体用法?Python task.task怎么用?Python task.task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类celery.task
的用法示例。
在下文中一共展示了task.task方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_worker_versions
# 需要导入模块: from celery import task [as 别名]
# 或者: from celery.task import task [as 别名]
def get_worker_versions():
""" Search and return the versions of Oasis components
"""
ktool_ver_str = subprocess.getoutput('fmcalc -v')
plat_ver_file = '/home/worker/VERSION'
if os.path.isfile(plat_ver_file):
with open(plat_ver_file, 'r') as f:
plat_ver_str = f.read().strip()
else:
plat_ver_str = ""
return {
"oasislmf": mdk_version,
"ktools": ktool_ver_str,
"platform": plat_ver_str
}
# When a worker connects send a task to the worker-monitor to register a new model
示例2: get_oasislmf_config_path
# 需要导入模块: from celery import task [as 别名]
# 或者: from celery.task import task [as 别名]
def get_oasislmf_config_path(model_id=None):
conf_var = settings.get('worker', 'oasislmf_config', fallback=None)
if not model_id:
model_id = settings.get('worker', 'model_id', fallback=None)
if conf_var:
return conf_var
if model_id:
model_root = settings.get('worker', 'model_data_directory', fallback='/var/oasis/')
model_specific_conf = Path(model_root, '{}-oasislmf.json'.format(model_id))
if model_specific_conf.exists():
return str(model_specific_conf)
return str(Path(model_root, 'oasislmf.json'))
# Send notification back to the API Once task is read from Queue
示例3: copy_setup_pages_task
# 需要导入模块: from celery import task [as 别名]
# 或者: from celery.task import task [as 别名]
def copy_setup_pages_task(copy_from_slug, copy_to_slug):
"""
Call copy_setup_pages as a task (since it can be slow with many pages).
"""
course_copy_from = CourseOffering.objects.get(slug=copy_from_slug)
course_copy_to = CourseOffering.objects.get(slug=copy_to_slug)
copy_setup_pages(course_copy_from, course_copy_to)
示例4: task
# 需要导入模块: from celery import task [as 别名]
# 或者: from celery.task import task [as 别名]
def task(*args, **kwargs):
def decorator(*args, **kwargs):
return None
return decorator
示例5: start_analysis_task
# 需要导入模块: from celery import task [as 别名]
# 或者: from celery.task import task [as 别名]
def start_analysis_task(self, analysis_pk, input_location, analysis_settings, complex_data_files=None):
"""Task wrapper for running an analysis.
Args:
self: Celery task instance.
analysis_settings (str): Path or URL to the analysis settings.
input_location (str): Path to the input tar file.
complex_data_files (list of complex_model_data_file): List of dicts containing
on-disk and original filenames for required complex model data files.
Returns:
(string) The location of the outputs.
"""
logging.info("LOCK_FILE: {}".format(settings.get('worker', 'LOCK_FILE')))
logging.info("LOCK_RETRY_COUNTDOWN_IN_SECS: {}".format(
settings.get('worker', 'LOCK_RETRY_COUNTDOWN_IN_SECS')))
with get_lock() as gotten:
if not gotten:
logging.info("Failed to get resource lock - retry task")
raise self.retry(
max_retries=None,
countdown=settings.getint('worker', 'LOCK_RETRY_COUNTDOWN_IN_SECS'))
logging.info("Acquired resource lock")
try:
notify_api_status(analysis_pk, 'RUN_STARTED')
self.update_state(state=RUNNING_TASK_STATUS)
output_location, traceback_location, log_location, return_code = start_analysis(
analysis_settings,
input_location,
complex_data_files=complex_data_files
)
except Exception:
logging.exception("Model execution task failed.")
raise
return output_location, traceback_location, log_location, return_code
示例6: on_error
# 需要导入模块: from celery import task [as 别名]
# 或者: from celery.task import task [as 别名]
def on_error(request, ex, traceback, record_task_name, analysis_pk, initiator_pk):
"""
Because of how celery works we need to include a celery task registered in the
current app to pass to the `link_error` function on a chain.
This function takes the error and passes it on back to the server so that it can store
the info on the analysis.
"""
signature(
record_task_name,
args=(analysis_pk, initiator_pk, traceback),
queue='celery'
).delay()
示例7: mltshp_task
# 需要导入模块: from celery import task [as 别名]
# 或者: from celery.task import task [as 别名]
def mltshp_task(*args, **options):
# This is how celery's periodic_task decorator customizes the class, so try it here too.
return task(**dict({"base": MltshpTask}, **options))
示例8: rerun_course
# 需要导入模块: from celery import task [as 别名]
# 或者: from celery.task import task [as 别名]
def rerun_course(source_course_key_string, destination_course_key_string, user_id, fields=None):
"""
Reruns a course in a new celery task.
"""
try:
# deserialize the payload
source_course_key = CourseKey.from_string(source_course_key_string)
destination_course_key = CourseKey.from_string(destination_course_key_string)
fields = deserialize_fields(fields) if fields else None
# use the split modulestore as the store for the rerun course,
# as the Mongo modulestore doesn't support multiple runs of the same course.
store = modulestore()
with store.default_store('split'):
store.clone_course(source_course_key, destination_course_key, user_id, fields=fields)
# set initial permissions for the user to access the course.
initialize_permissions(destination_course_key, User.objects.get(id=user_id))
# update state: Succeeded
CourseRerunState.objects.succeeded(course_key=destination_course_key)
return "succeeded"
except DuplicateCourseError as exc:
# do NOT delete the original course, only update the status
CourseRerunState.objects.failed(course_key=destination_course_key)
logging.exception(u'Course Rerun Error')
return "duplicate course"
# catch all exceptions so we can update the state and properly cleanup the course.
except Exception as exc: # pylint: disable=broad-except
# update state: Failed
CourseRerunState.objects.failed(course_key=destination_course_key)
logging.exception(u'Course Rerun Error')
try:
# cleanup any remnants of the course
modulestore().delete_course(destination_course_key, user_id)
except ItemNotFoundError:
# it's possible there was an error even before the course module was created
pass
return "exception: " + unicode(exc)