当前位置: 首页>>代码示例>>Python>>正文


Python states.SUCCESS属性代码示例

本文整理汇总了Python中celery.states.SUCCESS属性的典型用法代码示例。如果您正苦于以下问题:Python states.SUCCESS属性的具体用法?Python states.SUCCESS怎么用?Python states.SUCCESS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在celery.states的用法示例。


在下文中一共展示了states.SUCCESS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_task_state

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [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.") 
开发者ID:apache,项目名称:airflow,代码行数:24,代码来源:celery_executor.py

示例2: drop_clusters

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def drop_clusters(self, exclude_task_ids: Set = None, exclude_project_clustering_id: int = None):
        project = self
        # Stop running tusks
        from apps.task.tasks import purge_task
        from apps.project.tasks import ClusterProjectDocuments
        task_qr = project.project_tasks \
            .filter(name=ClusterProjectDocuments.name, status__in=UNREADY_STATES)  # type: QuerySet
        if exclude_task_ids:
            task_qr = task_qr.exclude(pk__in=exclude_task_ids)

        for task in task_qr:
            purge_task(task.pk, wait=True, timeout=1.5)
        # delete DocumentClusters
        for pcl in project.projectclustering_set.all():
            pcl.document_clusters.all().delete()
        # delete ProjectClustering
        project.projectclustering_set.exclude(id=exclude_project_clustering_id).delete()
        # delete ClusterProjectDocuments Tasks
        to_delete_qr = project.project_tasks.filter(name=ClusterProjectDocuments.name,
                                                    status__in=[SUCCESS, PENDING])  # type: QuerySet
        if exclude_task_ids:
            to_delete_qr = to_delete_qr.exclude(pk__in=exclude_task_ids)
        to_delete_qr.delete() 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:25,代码来源:models.py

示例3: process_tasks

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [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 
开发者ID:google,项目名称:turbinia,代码行数:27,代码来源:task_manager.py

示例4: _set_task_event

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def _set_task_event(self, event: dict) -> Iterator[Union[Task, str]]:
        task = self.memory.tasks.get(event['uuid'])
        pre_state = task and task.state
        (task, _), _ = self.memory.event(event)

        # fix or insert fields.
        task.result_meta = None
        if task.state == SUCCESS:
            task.result_meta, task.result = self._derive_task_result(task)
        yield task

        # fix shortcomings of `created` field: a task should be displayed as PENDING if not
        # new; if a task is first seen in any other state, it should not be new.
        if not pre_state:
            yield '' if task.state == PENDING else task.state  # empty state will mean new.
            return

        yield from self.gen_task_states.states_through(pre_state, task.state) 
开发者ID:rsalmei,项目名称:clearly,代码行数:20,代码来源:event_listener.py

示例5: wait_for_command

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [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
        }) 
开发者ID:palfrey,项目名称:wharf,代码行数:23,代码来源:views.py

示例6: xxx_backend

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def xxx_backend(self):
        tid = uuid()

        assert self.b.get_status(tid) == states.PENDING
        assert self.b.get_result(tid) is None

        self.b.mark_as_done(tid, 42)
        assert self.b.get_status(tid) == states.SUCCESS
        assert self.b.get_result(tid) == 42

        tid2 = uuid()
        try:
            raise KeyError('foo')
        except KeyError as exception:
            self.b.mark_as_failure(tid2, exception)

        assert self.b.get_status(tid2) == states.FAILURE
        assert isinstance(self.b.get_result(tid2), KeyError) 
开发者ID:guohongze,项目名称:adminset,代码行数:20,代码来源:test_database.py

示例7: task_completed

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def task_completed(sender=None, **kwargs):
    task_kwargs = kwargs.get('kwargs')
    job_id = task_kwargs.get('wooey_job')
    # Just return if it is not a wooey_job!
    if not job_id:
        return

    from .models import WooeyJob
    from celery import states
    try:
        job = WooeyJob.objects.get(pk=job_id)
    except (InterfaceError, DatabaseError) as e:
        db.connection.close()
        job = WooeyJob.objects.get(pk=job_id)
    state = kwargs.get('state')
    if state:
        job.status = WooeyJob.COMPLETED if state == states.SUCCESS else state
    job.celery_id = kwargs.get('task_id')
    job.save() 
开发者ID:wooey,项目名称:Wooey,代码行数:21,代码来源:signals.py

示例8: save

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def save(self, status):
        """Save task log entry if result is not None"""
        if hasattr(status, '__iter__'):
            status = [i for i in status if i is not None]  # remove None from result

            if status:
                success = all(status)
            else:
                success = None
        else:
            success = status

        if success is None:
            return

        if success:
            task_status = states.SUCCESS
        else:
            task_status = states.FAILURE

        task_log(self.task_id, self.msg, obj=self.obj, task_status=task_status, task_result=True,
                 detail=self.get_detail(), dc_id=self.dc_id, update_user_tasks=False) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:24,代码来源:log.py

示例9: format_task_status_class_filter

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [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' 
开发者ID:Salamek,项目名称:gitlab-tools,代码行数:16,代码来源:middleware.py

示例10: on_success

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def on_success(self, retval, task_id, args, kwargs):
        self.update_state(
            state=states.SUCCESS,
            meta={
                'filename': os.path.basename(args[0])
            }
        ) 
开发者ID:danieluhricek,项目名称:LiSa,代码行数:9,代码来源:tasks.py

示例11: get

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def get(self, task_id):
        task = celery.AsyncResult(task_id)  # task_2 = AsyncResult(id=task_id, app=celery)
        state = task.state
        info = task.info if task.info else {}
        result = {
            'state': state
        }

        if (state == states.PENDING):
            try:
                result['currentTask'] = info.get('desc', 'Processing Data')
            except AttributeError:
                state = states.FAILURE
                result['state'] = states.FAILURE
                result['currentTask'] = task.info

        elif (state == states.SUCCESS):
            result['result'] = info.get('result', None)

        elif (state == states.FAILURE):
            if info:
                error_type = type(info).__name__
                error_message = '%s: %s' % (error_type, str(info))
            else:
                error_type = None
                error_message = 'Unknown error occurred'
            result['error'] = error_message

        response = jsonify(result, status=task_state_to_code[state])
        return response 
开发者ID:MacroConnections,项目名称:DIVE-backend,代码行数:32,代码来源:task_resources.py

示例12: task_completed

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def task_completed(sender=None, **kwargs):
    task_kwargs = kwargs.get('kwargs')
    job_id = task_kwargs.get('djangui_job')
    from .models import DjanguiJob
    from celery import states
    try:
        job = DjanguiJob.objects.get(pk=job_id)
    except (InterfaceError, DatabaseError) as e:
        db.connection.close()
        job = DjanguiJob.objects.get(pk=job_id)
    state = kwargs.get('state')
    if state:
        job.status = DjanguiJob.COMPLETED if state == states.SUCCESS else state
    job.celery_id = kwargs.get('task_id')
    job.save() 
开发者ID:Chris7,项目名称:django-djangui,代码行数:17,代码来源:signals.py

示例13: document_tasks_progress

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def document_tasks_progress(self, details=False):
        """
        Progress per document (avg session document tasks progress)
        """
        result = self.document_set.annotate(document_id=models.F('id')) \
            .values('document_id', 'name', 'file_size', 'processed')
        for i in result:
            i['tasks_overall_status'] = SUCCESS if i['processed'] is True else None
        result = {i['name']: i for i in result}

        for file_name, task_progress_data in itertools.groupby(
                sorted(self.session_tasks_progress, key=lambda i: i['file_name']),
                key=lambda i: i['file_name']):
            task_progress_data = list(task_progress_data)
            document_progress = round(sum([int(i.get('task_progress') or 0) for i in task_progress_data]), 2)
            task_statuses = {i['task_status'] for i in task_progress_data}
            if None in task_statuses or PENDING in task_statuses:
                task_status = PENDING
            elif task_statuses == {SUCCESS}:
                task_status = SUCCESS
            else:
                task_status = FAILURE

            file_data = result.get(file_name, {'document_id': None, 'file_size': None, 'processed': False})
            file_data.update({'file_name': file_name, 'tasks_overall_status': task_status,
                              'document_progress': document_progress if task_status == PENDING else 100.0})

            if details:
                file_data['task_progress_data'] = task_progress_data

            result[file_name] = file_data
        # store result for further processing in status() and document_tasks_progress_total()
        self._document_tasks_progress = result
        return result 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:36,代码来源:models.py

示例14: set_status_by_task

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [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']) 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:17,代码来源:models.py

示例15: update_progress

# 需要导入模块: from celery import states [as 别名]
# 或者: from celery.states import SUCCESS [as 别名]
def update_progress(self,
                        new_progress: int,
                        succeeded: bool = True):
        new_progress = min(new_progress, 100)
        self.own_progress = new_progress
        if self.own_progress == 100:
            self.own_status = SUCCESS if succeeded else FAILURE
            now_time = now()
            self.own_date_done = self.own_date_done or now_time

        try:
            if self.has_sub_tasks:
                self.save(update_fields=['own_progress', 'own_status', 'own_date_done'])
            else:
                self.status = self.own_status
                self.progress = self.own_progress
                self.date_done = self.own_date_done
                self.save(update_fields=['progress', 'own_progress',
                                         'status', 'own_status',
                                         'date_done', 'own_date_done'])
        except DatabaseError:
            # task itself might have been deleted
            pass

    # We don't propagate changes to the parent tasks here because it is done in a serial manner
    # in a Celery-beat task - see apps.task.celery_backend.managers.update_parent_task().
    # update_parent_task() should be the only method to manipulate with the parent-child status updates.
    # Otherwise we will get the logic duplication and confusion.
    # If putting something here please take into account that we have:
    # - sub-task hierarchy;
    # - sub-tasks started when all other sub-tasks succeeded;
    # - sub-tasks started when some other sub-task failed;
    # - status of the parent task calculated based on its sub-tasks/fail-handler/success-handler;
    # - progress of the parent task calculated based on its sub-tasks/fail-handler/success-handler. 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:36,代码来源:models.py


注:本文中的celery.states.SUCCESS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。