Store return value and status of an executed task.
439636
def _store_result(self, task_id, result, status,
                      traceback=None, request=None):
        """"""
        self.TaskModel._default_manager.store_result(
            task_id, result, status,
            traceback=traceback, children=self.current_task_children(request),
        )
        return result
465974
def do_some_work(
        self,
        work_dict):
    

    label = "do_some_work"

    log.info(("task - {} - start "
              "work_dict={}")
             .format(label,
                     work_dict))

    ret_data = {
        "job_results": ("some response key={}").format(
                            str(uuid.uuid4()))
    }

    log.info(("task - {} - result={} done")
             .format(
                 ret_data,
                 label))

    return ret_data
204715
def sync(func):
    """"""
    sync_timeout = 3600  # Match standard synchronous timeout.

    def wraps(*args, **kwargs):
        task = func(*args, **kwargs)
        task.wait_for_result(timeout=sync_timeout)
        result = json.loads(task.result)
        return result

    return wraps
1100822
def status_search(self, status):
        """"""
        json = self._fetch_json()
        jobs = json['response']
        for job in jobs:
            job_info = jobs[job]
            if job_info['status'].lower() == status.lower():
                yield self._build_results(jobs, job)
1016805
def get_results(self, **kwargs):
        
        # Check whether the process completed.
        if self.returncode is None:
            raise self.Error("return code is None, you should call wait, communicate or poll")

        if self.status is None or self.status < self.S_DONE:
            raise self.Error("Task is not completed")

        return self.Results.from_node(self)
109444
private TaskRecord waitForTaskStatus(Tenant tenant, Task task, Predicate<TaskStatus> pred) {
        TaskRecord taskRecord = null;
        while (true) {
            Iterator<DColumn> colIter =
                DBService.instance(tenant).getAllColumns(TaskManagerService.TASKS_STORE_NAME, task.getTaskID()).iterator();
            if (!colIter.hasNext()) {
                taskRecord = storeTaskRecord(tenant, task);
            } else {
                taskRecord = buildTaskRecord(task.getTaskID(), colIter);
            }
            if (pred.test(taskRecord.getStatus())) {
                break;
            }
            try { Thread.sleep(TASK_CHECK_MILLIS); } catch (InterruptedException e) { }
        };
        return taskRecord;
    }
391823
def _get_status(self):
        """"""
        if self._state in ["processed", "error"]:
            return self._state
        
        get_resp = requests.get(self.location, cookies={"session": self.session})

        self._state = get_resp.json()["status"]
        self.slice_time = get_resp.json()["slice_time"]
        
        return self._state
696902
def _retrieve_result(endpoints, token_header):
        """"""
        request_list = [
            (url, token_header)
            for (task_id, url) in endpoints
        ]

        responses = concurrent_get(request_list)

        # Quick sanity check
        assert len(endpoints) == len(responses)

        responses_dic = {
            task_id: r.content
            for (task_id, _), r in zip(endpoints, responses)
        }
        return responses_dic
26807
def reset(self):
        
        if self._status is not TaskStatus.STOPPED:
            raise RuntimeError("Cannot reset %s in state %s" %
                               (self, self._status))
        self._reset()
        self.return_values = {}
        self._status = TaskStatus.IDLE
876652
def results(self):
        """"""
        tt = None
        for i, tf in enumerate(self[:-1]):
            tt = self[i+1]
            q = Queue(tf.qsize)
            tf.set_out(q, tt.workers)
            tt.set_in(q, tf.workers)

        if tt is None: # we have only one pool
            tt = self[0]
        q = Queue(tt.qsize)
        err_q = Queue()
        tt.set_out(q, 1)

        for t in self:
            t.set_err(err_q)
            t._start()

        for item in iterqueue(q, tt.workers):
            yield item

        errors = list(iterqueue(err_q, sum(t.workers for t in self)))

        for t in self:
            t._join()

        if len(errors) > 0:
            task_name, ex = errors[0]
            if len(errors) == 1:
                msg = 'The task "%s" raised %s' % (task_name, repr(ex),)
            else:
                msg = '%d tasks raised an exeption. First error reported on task "%s": %s' % (len(errors), task_name, repr(ex))

            raise TaskException(msg)
462153
async def result_continuation(task):
    """"""
    await asyncio.sleep(0.1)
    num, res = task.result()
    return num, res * 2
958304
def StoreResults(self, responses):
    """"""
    client_id = responses.request.client_id

    if responses.success:
      logging.info("Client %s has a file %s.", client_id, self.args.filename)
    else:
      logging.info("Client %s has no file %s.", client_id, self.args.filename)

    self.MarkClientDone(client_id)
38787
def set_status(self, instance, status):
        """"""
        status_key = self.get_status_key(instance)
        cache.set(status_key, status, timeout=300)
661244
def is_successful(self, retry=False):
        

        if not self.is_terminated(retry=retry):
            return False
        retry_num = options.retry_times
        while retry_num > 0:
            try:
                statuses = self.get_task_statuses()
                return all(task.status == Instance.Task.TaskStatus.SUCCESS
                           for task in statuses.values())
            except (errors.InternalServerError, errors.RequestTimeTooSkewed):
                retry_num -= 1
                if not retry or retry_num <= 0:
                    raise
356747
def get_state(self):
        """"""
        return {"started": (True if self.background_process and
                            self.background_process.is_alive() else False),
                "paused": self._pause.value,
                "stopped": self._end.value,
                "tasks": len(self.current_tasks),
                "busy_tasks": len(self.busy_tasks),
                "free_tasks": len(self.free_tasks)}
682189
def status_counter(self):
        
        counter = collections.Counter()

        for task in self:
            counter[str(task.status)] += 1

        return counter
161771
async def result_processor(tasks):
    """"""
    output = {}
    for task in tasks:
        num, res = await task
        output[num] = res
    return output