本文整理匯總了Python中celery.states.STARTED屬性的典型用法代碼示例。如果您正苦於以下問題:Python states.STARTED屬性的具體用法?Python states.STARTED怎麽用?Python states.STARTED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類celery.states
的用法示例。
在下文中一共展示了states.STARTED屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import STARTED [as 別名]
def __init__(self, target_task_id=None, target_status=STARTED, target_result=None, target_traceback=None):
self.target_task_id = target_task_id
self.revoke_kwargs = {}
self.revoke_called = False
self.target_status = target_status
self.target_result = target_result
self.target_traceback = target_traceback
class FakeAsyncResult(object):
def __init__(_self, task_id):
if task_id != target_task_id:
raise ValueError()
_self.id = task_id
_self.status = self.target_status
_self.result = self.target_result
_self.traceback = self.target_traceback
def revoke(_self, **kwargs):
self.revoke_called = True
self.revoke_kwargs = kwargs
self.fake_res = FakeAsyncResult
示例2: process_tasks
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import STARTED [as 別名]
def process_tasks(self):
"""Determine the current state of our tasks.
Returns:
list[TurbiniaTask]: all completed tasks
"""
completed_tasks = []
for task in self.tasks:
celery_task = task.stub
if not celery_task:
log.debug('Task {0:s} not yet created'.format(task.stub.task_id))
elif celery_task.status == celery_states.STARTED:
log.debug('Task {0:s} not finished'.format(celery_task.id))
elif celery_task.status == celery_states.FAILURE:
log.warning('Task {0:s} failed.'.format(celery_task.id))
completed_tasks.append(task)
elif celery_task.status == celery_states.SUCCESS:
task.result = workers.TurbiniaTaskResult.deserialize(celery_task.result)
completed_tasks.append(task)
else:
log.debug('Task {0:s} status unknown'.format(celery_task.id))
outstanding_task_count = len(self.tasks) - len(completed_tasks)
log.info('{0:d} Tasks still outstanding.'.format(outstanding_task_count))
return completed_tasks
示例3: wait_for_command
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import STARTED [as 別名]
def wait_for_command(request, app_name, task_id, after):
res = AsyncResult(task_id)
if app_name != '_':
app = models.App.objects.get(name=app_name)
task, created = models.TaskLog.objects.get_or_create(task_id=task_id, defaults={'app': app, 'when': datetime.now()})
description = task.description
else:
description = ""
if res.state == state(SUCCESS):
return redirect(reverse(after, kwargs={'app_name': app_name, 'task_id': task_id}))
log = ansi_escape.sub("", get_log(res))
if res.state == state(FAILURE):
log += str(res.traceback)
return render(request, 'command_wait.html', {
'app': app_name,
'task_id': task_id,
'log': log,
'state': res.state,
'running': res.state in [state(PENDING), state(STARTED)],
'description': description
})
示例4: format_task_status_class_filter
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import STARTED [as 別名]
def format_task_status_class_filter(task_result: TaskResult=None) -> str:
if task_result:
return {
states.SUCCESS: 'success',
states.FAILURE: 'danger',
states.REVOKED: 'danger',
states.REJECTED: 'danger',
states.RETRY: 'warning',
states.PENDING: 'info',
states.RECEIVED: 'info',
states.STARTED: 'info',
}.get(task_result.taskmeta.status, 'warning')
return 'warning'
示例5: setup_task_states
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import STARTED [as 別名]
def setup_task_states() -> ExpectedStateHandler:
terminal = (SUCCESS, FAILURE, REJECTED, REVOKED)
pending = ExpectedPath(PENDING)
received = pending.to(RECEIVED)
received.to(STARTED) \
.to(terminal, RETRY) \
.to(pending, received)
return ExpectedStateHandler(pending)
示例6: check_letsencrypt
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import STARTED [as 別名]
def check_letsencrypt(request, app_name, task_id):
res = AsyncResult(task_id)
log = get_log(res)
if log.find("Certificate retrieved successfully") !=-1:
clear_cache("letsencrypt:ls")
return redirect(reverse('app_info', args=[app_name]))
else:
return render(request, 'command_wait.html', {'app': app_name, 'task_id': task_id, 'log': log, 'state': res.state, 'running': res.state in [state(PENDING), state(STARTED)]})
示例7: get_task_result
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import STARTED [as 別名]
def get_task_result(task, task_id):
"""
Convert Celery Task Object into dict.
"""
# get result dict
result = get_result(task)
state = _get_task_state(task)
if state in TASK_STATE_PENDING: # Hide STARTED result
result = None
elif isinstance(result, dict):
# Let's make a copy, because we will later remove 'meta' and this will
# happen in memory. So if someone uses this same reference, we could have a
# problem. See #105
result = result.copy()
try:
del result['meta']
except KeyError:
pass
try:
del result['json']
except KeyError:
pass
tr = {
'task_id': task_id,
'status': state,
'result': result,
}
return tr