本文整理匯總了Python中celery.states.REVOKED屬性的典型用法代碼示例。如果您正苦於以下問題:Python states.REVOKED屬性的具體用法?Python states.REVOKED怎麽用?Python states.REVOKED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類celery.states
的用法示例。
在下文中一共展示了states.REVOKED屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: update_task_state
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [as 別名]
def update_task_state(self, key: TaskInstanceKeyType, state: str, info: Any) -> None:
"""Updates state of a single task."""
# noinspection PyBroadException
try:
if self.last_state[key] != state:
if state == celery_states.SUCCESS:
self.success(key, info)
del self.tasks[key]
del self.last_state[key]
elif state == celery_states.FAILURE:
self.fail(key, info)
del self.tasks[key]
del self.last_state[key]
elif state == celery_states.REVOKED:
self.fail(key, info)
del self.tasks[key]
del self.last_state[key]
else:
self.log.info("Unexpected state: %s", state)
self.last_state[key] = state
except Exception: # pylint: disable=broad-except
self.log.exception("Error syncing the Celery executor, ignoring it.")
示例2: format_task_status_class_filter
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [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'
示例3: celery_status
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [as 別名]
def celery_status(request):
# TODO: This function can use some sprucing up, design a better data structure for returning jobs
spanbase = "<span class='glyphicon {}' data-toggle='tooltip' data-trigger='hover' title='{}'></span>"
STATE_MAPPER = {
DjanguiJob.COMPLETED: spanbase.format('glyphicon-ok', _('Success')),
DjanguiJob.RUNNING: spanbase.format('glyphicon-refresh spinning', _('Executing')),
states.PENDING: spanbase.format('glyphicon-time', _('In queue')),
states.REVOKED: spanbase.format('glyphicon-stop', _('Halted')),
DjanguiJob.SUBMITTED: spanbase.format('glyphicon-hourglass', _('Waiting to be queued'))
}
user = request.user
if user.is_superuser:
jobs = DjanguiJob.objects.all()
else:
jobs = DjanguiJob.objects.filter(Q(user=None) | Q(user=user) if request.user.is_authenticated() else Q(user=None))
jobs = jobs.exclude(status=DjanguiJob.DELETED)
# divide into user and anon jobs
def get_job_list(job_query):
return [{'job_name': escape(job.job_name), 'job_status': STATE_MAPPER.get(job.status, job.status),
'job_submitted': job.created_date.strftime('%b %d %Y, %H:%M:%S'),
'job_id': job.pk,
'job_description': escape(six.u('Script: {}\n{}').format(job.script.script_name, job.job_description)),
'job_url': reverse('djangui:celery_results_info', kwargs={'job_id': job.pk})} for job in job_query]
d = {'user': get_job_list([i for i in jobs if i.user == user]),
'anon': get_job_list([i for i in jobs if i.user == None or (user.is_superuser and i.user != user)])}
return JsonResponse(d, safe=False)
示例4: celery_task_command
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [as 別名]
def celery_task_command(request):
command = request.POST.get('celery-command')
job_id = request.POST.get('job-id')
job = DjanguiJob.objects.get(pk=job_id)
response = {'valid': False,}
valid = valid_user(job.script, request.user)
if valid.get('valid') is True:
user = request.user if request.user.is_authenticated() else None
if user == job.user or job.user == None:
if command == 'resubmit':
new_job = job.submit_to_celery(resubmit=True, user=request.user)
response.update({'valid': True, 'extra': {'task_url': reverse('djangui:celery_results_info', kwargs={'job_id': new_job.pk})}})
elif command == 'rerun':
job.submit_to_celery(user=request.user, rerun=True)
response.update({'valid': True, 'redirect': reverse('djangui:celery_results_info', kwargs={'job_id': job_id})})
elif command == 'clone':
response.update({'valid': True, 'redirect': '{0}?job_id={1}'.format(reverse('djangui:djangui_task_launcher'), job_id)})
elif command == 'delete':
job.status = DjanguiJob.DELETED
job.save()
response.update({'valid': True, 'redirect': reverse('djangui:djangui_home')})
elif command == 'stop':
celery_app.control.revoke(job.celery_id, signal='SIGKILL', terminate=True)
job.status = states.REVOKED
job.save()
response.update({'valid': True, 'redirect': reverse('djangui:celery_results_info', kwargs={'job_id': job_id})})
else:
response.update({'errors': {'__all__': [force_text(_("Unknown Command"))]}})
else:
response.update({'errors': {'__all__': [force_text(valid.get('error'))]}})
return JsonResponse(response)
示例5: complete_job
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [as 別名]
def complete_job(status):
from ..models import DjanguiJob
from celery import states
return status in (DjanguiJob.COMPLETED, states.REVOKED)
示例6: set_status_by_task
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [as 別名]
def set_status_by_task(self):
if not self.task:
return
new_status = self.status
if self.task.status in {FAILURE, REVOKED}:
new_status = FAILURE
elif self.status == SUCCESS:
new_status = SUCCESS
elif self.status in UNREADY_STATES:
new_status = PENDING
if new_status == self.status:
return
self.status = new_status
self.save(update_fields=['status'])
示例7: _task_state
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [as 別名]
def _task_state(state: str) -> None:
if state == SUCCESS: # final state in BOLD
return Colors.GREEN_BOLD(state, HEADER_ALIGN)
if state in (FAILURE, REVOKED, REJECTED): # final too
return Colors.RED_BOLD(state, HEADER_ALIGN)
if state == RETRY: # transient state with a failure.
return Colors.ORANGE(state, HEADER_ALIGN)
return Colors.YELLOW(state, HEADER_ALIGN) # transient states
示例8: setup_task_states
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [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)
示例9: celery_task_command
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [as 別名]
def celery_task_command(request):
command = request.POST.get('celery-command')
job_id = request.POST.get('job-id')
job = WooeyJob.objects.get(pk=job_id)
response = {'valid': False, }
valid = valid_user(job.script_version.script, request.user)
if valid.get('valid') == True:
user = request.user if request.user.is_authenticated else None
if user == job.user or job.user == None:
if command == 'resubmit':
new_job = job.submit_to_celery(resubmit=True, user=request.user)
response.update({'valid': True, 'extra': {'job_url': reverse('wooey:celery_results', kwargs={'job_id': new_job.pk})}})
elif command == 'rerun':
job.submit_to_celery(user=request.user, rerun=True)
response.update({'valid': True, 'redirect': reverse('wooey:celery_results', kwargs={'job_id': job_id})})
elif command == 'delete':
job.status = WooeyJob.DELETED
job.save()
response.update({'valid': True, 'redirect': reverse('wooey:wooey_home')})
elif command == 'stop':
celery_app.control.revoke(job.celery_id, signal='SIGKILL', terminate=True)
job.status = states.REVOKED
job.save()
response.update({'valid': True, 'redirect': reverse('wooey:celery_results', kwargs={'job_id': job_id})})
else:
response.update({'errors': {'__all__': [force_text(_("Unknown Command"))]}})
else:
response.update({'errors': {'__all__': [force_text(valid.get('error'))]}})
return JsonResponse(response)
示例10: complete_job
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [as 別名]
def complete_job(status):
from ..models import WooeyJob
from celery import states
return status in (WooeyJob.COMPLETED, states.REVOKED)
示例11: _get_stats_result
# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import REVOKED [as 別名]
def _get_stats_result(basequery):
def get_count(state):
return basequery.filter(status=state).aggregate(count=Count('id')).get('count', 0)
return {
'pending': get_count(states.PENDING),
'revoked': get_count(states.REVOKED),
'succeeded': get_count(states.SUCCESS),
'failed': get_count(states.FAILURE),
}