Run a single task in another process saving the result to our list of pending results.
        :param task: Task: function and data we can run in another process
        :param parent_result: object: result from our parent task
761858
def execute_task(self, task, parent_result):
        
        task.before_run(parent_result)
        context = task.create_context(self.message_queue)
        pending_result = self.pool.apply_async(execute_task_async, (task.func, task.id, context))
        self.pending_results.append(pending_result)
1125194
def perform_task(self, service, task_name, account, payload, callback=None):
        
        data = {
            'service': service,
            'action': task_name,
            'account': account,
        }
        data.update(payload)

        response = self._perform_post_request(self.submit_endpoint, data, self.token_header)

        task = Task(uuid=response['task_id'], callback=callback)
        self._pending_tasks[task.uuid] = task

        return task
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)
344777
async def run_task(self, container, task, newthread = False):
        ""
        e = TaskEvent(self, task=task, newthread = newthread)
        await container.wait_for_send(e)
        ev = await TaskDoneEvent.createMatcher(e)
        if hasattr(ev, 'exception'):
            raise ev.exception
        else:
            return ev.result
1218409
def run(self):
        
        if not self._has_yielded and not self.task.local_workflow_require_branches:
            self._has_yielded = True

            yield list(self.task.get_branch_tasks().values())

        self._has_run = True
675575
def run(self):
        
        for task in self.get_next_tasks(None):
            self.executor.add_task(task, None)
        while not self.executor.is_done():
            done_task_and_result = self.executor.wait_for_tasks()
            for task, task_result in done_task_and_result:
                self._add_sub_tasks_to_executor(task, task_result)
914548
def on_success(self, retval, task_id, args, kwargs):
        
        if self.request.is_eager:
            # Store the result because celery wouldn't otherwise
            self.update_state(task_id, SUCCESS, retval)
261863
def run(self):
        """"""
        (task_id, tasks) = self.server.get_task()
        self.task_store.from_dict(tasks)
        for (index, task) in self.task_store:
            result = self.compute(index, task)
            self.results.append(result)
        self.server.task_done((task_id, self.results))
1241036
def build_and_run_task(task_class, params = nil)
      task_run = TaskRun.new(task_class, params)
      @task_run_stack.last.runs << task_run

      @task_run_stack.push(task_run)
      task = super(task_class, params)
      @task_run_stack.pop
      task
    end
1066653
public void postTask( Runnable task )
  {
    synchronized( _queue )
    {
      _queue.add( task );

      if( !isAlive() )
      {
        start();
      }

      _queue.notifyAll();
    }
  }
100829
def _finish_task_processing(self, queue, task, success):
        
        log = self.log.bind(queue=queue, task_id=task.id)

        def _mark_done():
            # Remove the task from active queue
            task._move(from_state=ACTIVE)
            log.info('done')

        if success:
            _mark_done()
        else:
            should_retry = False
            should_log_error = True
            # Get execution info (for logging and retry purposes)
            execution = self.connection.lindex(
                self._key('task', task.id, 'executions'), -1)

            if execution:
                execution = json.loads(execution)

            if execution and execution.get('retry'):
                if 'retry_method' in execution:
                    retry_func, retry_args = execution['retry_method']
                else:
                    # We expect the serialized method here.
                    retry_func, retry_args = serialize_retry_method( \
                            self.config['DEFAULT_RETRY_METHOD'])
                should_log_error = execution['log_error']
                should_retry = True

            if task.retry_method and not should_retry:
                retry_func, retry_args = task.retry_method
                if task.retry_on:
                    if execution:
                        exception_name = execution.get('exception_name')
                        try:
                            exception_class = import_attribute(exception_name)
                        except TaskImportError:
                            log.error('could not import exception',
                                      exception_name=exception_name)
                        else:
                            if task.should_retry_on(exception_class, logger=log):
                                should_retry = True
                else:
                    should_retry = True

            state = ERROR

            when = time.time()

            log_context = {
                'func': task.serialized_func
            }

            if should_retry:
                retry_num = task.n_executions()
                log_context['retry_func'] = retry_func
                log_context['retry_num'] = retry_num

                try:
                    func = import_attribute(retry_func)
                except TaskImportError:
                    log.error('could not import retry function',
                              func=retry_func)
                else:
                    try:
                        retry_delay = func(retry_num, *retry_args)
                        log_context['retry_delay'] = retry_delay
                        when += retry_delay
                    except StopRetry:
                        pass
                    else:
                        state = SCHEDULED

            if execution:
                if state == ERROR and should_log_error:
                    log_func = log.error
                else:
                    log_func = log.warning

                log_context.update({
                    'time_failed': execution.get('time_failed'),
                    'traceback': execution.get('traceback'),
                    'exception_name': execution.get('exception_name'),
                })

                log_func('task error', **log_context)
            else:
                log.error('execution not found', **log_context)

            # Move task to the scheduled queue for retry, or move to error
            # queue if we don't want to retry.
            if state == ERROR and not should_log_error:
                _mark_done()
            else:
                task._move(from_state=ACTIVE, to_state=state, when=when)
884627
def CompleteTask(self, task):
    
    with self._lock:
      if task.identifier not in self._tasks_merging:
        raise KeyError('Task {0:s} was not merging.'.format(task.identifier))

      self.SampleTaskStatus(task, 'completed')

      del self._tasks_merging[task.identifier]

      logger.debug('Completed task {0:s}.'.format(task.identifier))
189130
def wait_and_join(self, task):
        
        while not task.has_started:
            time.sleep(self._polling_time)
        task.thread.join()
1122358
def create_pending_after_task(self):
        
        for task in self.settings.tasks[self.after_tasks_key]:
            self.after_tasks.append(task)
            self.after_results[task] = Result(task)
1225970
def on_result(self, task, result):
        ''''''
        if not result:
            return
        if 'taskid' in task and 'project' in task and 'url' in task:
            logger.info('result %s:%s %s -> %.30r' % (
                task['project'], task['taskid'], task['url'], result))
            return self.resultdb.save(
                project=task['project'],
                taskid=task['taskid'],
                url=task['url'],
                result=result
            )
        else:
            logger.warning('result UNKNOW -> %.30r' % result)
            return
1242499
def run(self):
        
        if self.tasks:
            logger.info('Registered tasks: %s' % ', '.join(self.tasks))
        else:
            logger.info('No tasks registered')
        logger.info('Listening on %s ...' % self.bind)
        self.socket.bind(self.bind)

        self.running = True
        self.pre_run()

        while self.running:
            msg = self.socket.recv_pyobj()

            action = msg.get('action')
            if action == 'run_task':
                if msg.get('name') not in self.tasks:
                    print(msg.get('name'))
                    print(self.tasks)
                    response = {
                        'success': False, 'exception': TaskNotFound(msg.get('name'))}
                    self.socket.send_pyobj(response)
                else:
                    task = Task(str(uuid.uuid4()), msg.get('name'), [], {})

                    if msg.get('args'):
                        task.args = msg.get('args', [])
                    if msg.get('kwargs'):
                        task.kwargs = msg.get('kwargs', {})

                    self.task_result_backend.add_task(task)

                    self.queue.put(task.id)
                    self.socket.send_pyobj({'success': True, 'task': task})
            elif action == 'get_result':
                task_id = msg.get('id')
                task = self.task_result_backend.get_task(task_id)
                if task:
                    response = {'success': True, 'task': task}
                else:
                    response = {
                        'success': False,
                        'id': task_id,
                        'exception': TaskNotFound(task_id)}
                self.socket.send_pyobj(response)
            elif action == 'wait':
                task_id = msg.get('id')
                task = self.task_result_backend.get_task(task_id)
                if task:
                    while not task.terminated:
                        task = self.task_result_backend.get_task(task_id)
                        time.sleep(1)
                    response = {'success': True, 'task': task}
                else:
                    response = {
                        'success': False,
                        'id': task_id,
                        'exception': TaskNotFound(task_id)}
                self.socket.send_pyobj(response)
            else:
                response = {'success': False, 'exception': MessageMalformed()}
                self.socket.send_pyobj(response)
421959
def run(self):
        '''
        '''
        if self.verbose:
            pbar = tqdm(total=100)
        while True:
            task_remain = self._task_queue.qsize()
            task_finished = int((float(self.total_task - task_remain) /
                                 float(self.total_task)) * 100)
            if task_finished % 20 == 0 and task_finished != self.current_state:
                self.current_state = task_finished
                logger.info('{0}% done'.format(task_finished))
                if self.verbose and task_finished > 0:
                    pbar.update(20)
            if task_remain == 0:
                break
        logger.debug('All task data cleared')