當前位置: 首頁>>代碼示例>>Python>>正文


Python states.FAILURE屬性代碼示例

本文整理匯總了Python中celery.states.FAILURE屬性的典型用法代碼示例。如果您正苦於以下問題:Python states.FAILURE屬性的具體用法?Python states.FAILURE怎麽用?Python states.FAILURE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在celery.states的用法示例。


在下文中一共展示了states.FAILURE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update_task_state

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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: process_tasks

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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

示例3: wait_for_command

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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

示例4: test_backend__pickle_serialization

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [as 別名]
def test_backend__pickle_serialization(self):
        self.app.conf.result_serializer = 'pickle'
        self.app.conf.accept_content = {'pickle', 'json'}
        self.b = DatabaseBackend(app=self.app)

        tid2 = uuid()
        result = {'foo': 'baz', 'bar': SomeClass(12345)}
        self.b.mark_as_done(tid2, result)
        # is serialized properly.
        rindb = self.b.get_result(tid2)
        assert rindb.get('foo') == 'baz'
        assert rindb.get('bar').data == 12345

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

        assert self.b.get_status(tid3) == states.FAILURE
        assert isinstance(self.b.get_result(tid3), KeyError) 
開發者ID:guohongze,項目名稱:adminset,代碼行數:23,代碼來源:test_database.py

示例5: xxx_backend

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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

示例6: save

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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

示例7: task_user_callback_cb

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [as 別名]
def task_user_callback_cb(task_id, parent_task_id, cb, **kwargs):
    """
    Task for calling remote url in user defined callback
    """
    try:
        obj = get_task_object(kwargs)
    except ObjectDoesNotExist:
        obj = None

    user = User.objects.get(id=user_id_from_task_id(parent_task_id))
    payload, status = get_task_status(parent_task_id)

    try:
        response = UserCallback(parent_task_id).request(cb, user.callback_key, payload)
    except RequestException as ex:
        status = states.FAILURE
        details = ex
    else:
        status = states.SUCCESS
        details = str(response.status_code) + ': ' + response.reason

    if cb.get('cb_log'):
        task_log(parent_task_id, LOG_REMOTE_CALLBACK, obj=obj, task_status=status, detail=details) 
開發者ID:erigones,項目名稱:esdc-ce,代碼行數:25,代碼來源:tasks.py

示例8: format_task_status_class_filter

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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

示例9: on_failure

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [as 別名]
def on_failure(self, exc, task_id, args, kwargs, einfo):
        self.update_state(
            state=states.FAILURE,
            meta={
                'exc_type': type(exc).__name__,
                'traceback': einfo.traceback,
                'filename': os.path.basename(args[0])
            }
        )
        self.traceback = einfo.traceback 
開發者ID:danieluhricek,項目名稱:LiSa,代碼行數:12,代碼來源:tasks.py

示例10: get

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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

示例11: worker_error_handler

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [as 別名]
def worker_error_handler(request, exc, traceback):
    task_id = request.id
    task = celery.AsyncResult(task_id)
    current_task.update_state(
        task_id=task_id,
        state=states.FAILURE,
        meta={ 'error': traceback }
    )
    logger.error('Task {0} raised exception: {1!r}\n{2!r}'.format(task_id, exc, traceback))
    # REPORT with raven
    # return traceback 
開發者ID:MacroConnections,項目名稱:DIVE-backend,代碼行數:13,代碼來源:handlers.py

示例12: document_tasks_progress

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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

示例13: set_status_by_task

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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

示例14: on_failure

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [as 別名]
def on_failure(self, exc, task_id, args, kwargs, exc_traceback):
        if self.project_clustering_id:
            project_clustering = ProjectClustering.objects.get(pk=self.project_clustering_id)
            project_clustering.status = FAILURE

            exc_str = str(exc)
            message_head = 'Clustering failed. '
            message_body = 'Unexpected error while clustering. Try again later.'
            low_features_message = 'Not enough data points for features ' \
                                   'of chosen "cluster by". Try adding documents, reducing number ' \
                                   'of clusters, or changing "cluster by" feature selection.'

            if ('max_df corresponds to < documents than min_df' in exc_str) or \
                    ('Number of samples smaller than number of clusters' in exc_str) or \
                    (re.search(r'n_samples=\d+ should be >= n_clusters=\d+', exc_str)) or \
                    (re.search(r'n_components=\d+ must be between 0 and min', exc_str)):
                message_body = low_features_message
            elif re.search(r'n_components=\d+ must be between \d+ and n_features=\d+', exc_str):
                message_body = 'Chosen documents look very similar,' \
                               ' clustering algorithm is not able to form clusters.'
            elif isinstance(exc, EmptyDataSetError):
                message_body = low_features_message
            else:
                message_body += ' \nOriginal issue is: "{}"'.format(exc_str)

            project_clustering.reason = message_head + message_body
            project_clustering.save()

        super().on_failure(exc, task_id, args, kwargs, exc_traceback) 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:31,代碼來源:tasks.py

示例15: update_progress

# 需要導入模塊: from celery import states [as 別名]
# 或者: from celery.states import FAILURE [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.FAILURE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。