Exemple #1
0
    def __call__(self, *args, **kwargs):
        options = kwargs.pop('_options', {})

        self.args = options.get('args', [])
        self.responsible = options.get('responsible')
        self.ip = options.get('ip')
        self.step = options.get('step')
        self.step_pos = options.get('step_pos')
        self.hidden = options.get('hidden', False) or self.hidden
        if options.get('hidden') is not None:
            self.hidden = options['hidden']

        self.undo_type = options.get('undo', False)
        self.result_params = options.get('result_params', {}) or {}
        self.task_id = options.get('task_id') or self.request.id
        self.eager = options.get('eager') or self.request.is_eager
        self.allow_failure = options.get('allow_failure') or self.allow_failure

        for k, v in self.result_params.items():
            kwargs[k] = get_result(self.step, v)

        if self.track:
            ProcessTask.objects.filter(celery_id=self.task_id).update(
                hidden=self.hidden,
            )

        try:
            user = User.objects.get(pk=self.responsible)
            if user.user_profile is not None:
                with translation.override(user.user_profile.language):
                    return self._run(*args, **kwargs)
        except User.DoesNotExist:
            pass

        return self._run(*args, **kwargs)
Exemple #2
0
    def get_params(self, obj):
        params = obj.params
        for param, task in obj.result_params.iteritems():
            try:
                params[param] = get_result(task)
            except ProcessTask.DoesNotExist:
                params[param] = 'waiting on result from %s ...' % task

        return dict((k.encode('utf-8'), v) for k, v in params.iteritems())
Exemple #3
0
    def get_params(self, obj):
        params = obj.params
        for param, task in obj.result_params.items():
            try:
                params[param] = get_result(task)
            except ProcessTask.DoesNotExist:
                params[param] = 'waiting on result from %s ...' % task

        return params
Exemple #4
0
    def __call__(self, *args, **kwargs):
        options = kwargs.pop('_options', {})
        self.chunk = options.get('chunk', False)

        self.args = options.get('args', [])
        self.responsible = options.get('responsible')
        self.ip = options.get('ip')
        if self.ip is not None:
            self.ip_objid = get_cached_objid(str(self.ip))
        self.step = options.get('step')
        self.step_pos = options.get('step_pos')
        self.hidden = options.get('hidden', False) or self.hidden
        self.undo_type = options.get('undo', False)
        self.result_params = options.get('result_params', {}) or {}
        self.task_id = options.get('task_id') or self.request.id
        self.eager = options.get('eager') or self.request.is_eager

        if self.chunk:
            res = []
            events = []
            if not connection.features.autocommits_when_autocommit_is_off:
                transaction.set_autocommit(False)
            try:
                for a in args:
                    a_options = a.pop('_options')
                    self.eager = True
                    self.task_id = a_options['task_id']
                    self.args = a_options['args']

                    self.progress = 0
                    hidden = a_options.get('hidden', False) or self.hidden
                    time_started = timezone.now()
                    try:
                        retval = self._run(*self.args, **a)
                    except:
                        ProcessTask.objects.filter(pk=self.task_id).update(
                            hidden=hidden,
                            time_started=time_started,
                            progress=self.progress)
                        einfo = ExceptionInfo()
                        if self.event_type:
                            self.create_event(self.task_id,
                                              celery_states.FAILURE, args, a,
                                              None, einfo)
                        raise
                    else:
                        self.success(retval, self.task_id, None, kwargs)
                        ProcessTask.objects.filter(pk=self.task_id).update(
                            result=retval,
                            status=celery_states.SUCCESS,
                            hidden=hidden,
                            time_started=time_started,
                            time_done=timezone.now(),
                            progress=100)
                        res.append(retval)
                        if self.event_type:
                            self.create_event(self.task_id,
                                              celery_states.SUCCESS, self.args,
                                              a, retval, None)
            except:
                raise
            else:
                return res
            finally:
                if not connection.features.autocommits_when_autocommit_is_off:
                    transaction.commit()
                    transaction.set_autocommit(True)

        for k, v in six.iteritems(self.result_params):
            kwargs[k] = get_result(v, self.eager)

        if self.track:
            ProcessTask.objects.filter(pk=self.task_id).update(
                hidden=self.hidden,
                status=celery_states.STARTED,
                time_started=timezone.now())

        return self._run(*args, **kwargs)
Exemple #5
0
    def get_params(self, obj):
        params = obj.params
        for param, reference in obj.result_params.items():
            params[param] = get_result(obj.processstep, reference)

        return params