Process tasks in queue.
191024
def _process_queue_tasks(self, queue, queue_lock, task_ids, now, log):
        """"""

        processed_count = 0

        # Get all tasks
        serialized_tasks = self.connection.mget([
            self._key('task', task_id) for task_id in task_ids
        ])

        # Parse tasks
        tasks = []
        for task_id, serialized_task in zip(task_ids, serialized_tasks):
            if serialized_task:
                task_data = json.loads(serialized_task)
            else:
                # In the rare case where we don't find the task which is
                # queued (see ReliabilityTestCase.test_task_disappears),
                # we log an error and remove the task below. We need to
                # at least initialize the Task object with an ID so we can
                # remove it.
                task_data = {'id': task_id}

            task = Task(self.tiger, queue=queue, _data=task_data,
                        _state=ACTIVE, _ts=now)

            if not serialized_task:
                # Remove task as per comment above
                log.error('not found', task_id=task_id)
                task._move()
            elif task.id != task_id:
                log.error('task ID mismatch', task_id=task_id)
                # Remove task
                task._move()
            else:
                tasks.append(task)

        # List of task IDs that exist and we will update the heartbeat on.
        valid_task_ids = set(task.id for task in tasks)

        # Group by task func
        tasks_by_func = OrderedDict()
        for task in tasks:
            func = task.serialized_func
            if func in tasks_by_func:
                tasks_by_func[func].append(task)
            else:
                tasks_by_func[func] = [task]

        # Execute tasks for each task func
        for tasks in tasks_by_func.values():
            success, processed_tasks = self._execute_task_group(queue,
                    tasks, valid_task_ids, queue_lock)
            processed_count = processed_count + len(processed_tasks)
            log.debug('processed', attempted=len(tasks),
                      processed=processed_count)
            for task in processed_tasks:
                self._finish_task_processing(queue, task, success)

        return processed_count
414476
public function process(): void
    {
        try {
            $this->queue = msg_get_queue(ftok(__FILE__, 't'));
            $this->catchSignal();
            $this->initWorkerManager();
            $this->main();
        } catch (\Exception $e) {
            $this->logger->error('main() throw an exception, cleanup and exit', [
                'class' => get_class($this),
                'exception' => $e,
            ]);

            $this->cleanup(SIGTERM);
        }
    }
1153656
def ProcessTask(self, target, args, name, queueing_time):
    """"""

    if self.pool.name:
      time_in_queue = time.time() - queueing_time
      stats_collector_instance.Get().RecordEvent(
          _QUEUEING_TIME_METRIC, time_in_queue, fields=[self.pool.name])

      start_time = time.time()
    try:
      target(*args)
    # We can't let a worker die because one of the tasks it has to process
    # throws an exception. Therefore, we catch every error that is
    # raised in the call to target().
    except Exception as e:  # pylint: disable=broad-except
      if self.pool.name:
        stats_collector_instance.Get().IncrementCounter(
            _TASK_EXCEPTIONS_METRIC, fields=[self.pool.name])
      logging.exception("Caught exception in worker thread (%s): %s", name,
                        str(e))

    if self.pool.name:
      total_time = time.time() - start_time
      stats_collector_instance.Get().RecordEvent(
          _WORKING_TIME_METRIC, total_time, fields=[self.pool.name])
277716
def run(self):
    """"""
    while not self._state.is_terminating:
      self._process_event_queue()
      self._state.maybe_pause()
1223988
def process_queues(self, forced=False):
        """"""

        with self.lock:
            if (not forced and not self.must_process) or not self.queues_enabled:
                return
            self.must_process = False
        ARBITRATOR.awaken()
748043
function queue(runner) {
    if (running < tasks) {
      ++running;
      runner(release);
    } else {
      pending.push(runner);
    }
  }
185876
def enqueue_jobs(self, jobs: Iterable[Job]):
        """"""
        for job in jobs:
            if job.should_start:
                job.status = JobStatus.QUEUED
                queue = self._get_queue(job.queue)
                queue.put(job.serialize())
            else:
                with self._lock:
                    job.status = JobStatus.WAITING
                    self._future_jobs.append(job.serialize())
                    self._future_jobs.sort(key=lambda j: Job.deserialize(j).at)
        self._something_happened.set()
238389
public final void process(Queue<String> argq, T state) {
    String[] args = argq.toArray(new String[argq.size()]);
    argq.clear();
    run(args, state);
  }
1280163
def flush(self, queue_name):
        
        for _ in iter_queue(self.queues[queue_name]):
            self.queues[queue_name].task_done()
1314158
def ProcessResponses(self, responses, thread_pool):
    """"""
    for response in responses:
      thread_pool.AddTask(
          target=self._SafeProcessMessage,
          args=(response,),
          name=self.__class__.__name__)
727562
function runQueue() {
		var lastReturned = returned instanceof Array ? returned : [returned]
		  , tasks = queued.shift();

		if (tasks) tasks = tasks.tasks;
		returned = undefined;

		if (tasks instanceof Array) {
			for (var t=0,tt=tasks.length; t<tt; t++) {
				tasks[t].apply(taskObject(t),lastReturned);
			};
			return;
		}
		if (typeof tasks == 'object') {
			for (var t in tasks) if (tasks.hasOwnProperty(t)) {
				tasks[t].apply(taskObject(t),lastReturned);
			}
			return;
		}
	}
264432
def flush(self):
        """"""
        while not self._queue.empty():
            self._queue.get()
            self._queue.task_done()
        self.close()
110873
def process_task(self):
        """"""
        if _debug: ClientSSM._debug("process_task")

        if self.state == SEGMENTED_REQUEST:
            self.segmented_request_timeout()
        elif self.state == AWAIT_CONFIRMATION:
            self.await_confirmation_timeout()
        elif self.state == SEGMENTED_CONFIRMATION:
            self.segmented_confirmation_timeout()
        elif self.state == COMPLETED:
            pass
        elif self.state == ABORTED:
            pass
        else:
            e = RuntimeError("invalid state")
            ClientSSM._exception("exception: %r", e)
            raise e
592254
def flush_queue(self):
        """"""
        records = []

        while not self.queue.empty() and len(records) < self.batch_size:
            records.append(self.queue.get())

        if records:
            self.send_records(records)
            self.last_flush = time.time()
120479
def wait_for_tasks(self):
        
        finished_tasks_and_results = []
        while len(finished_tasks_and_results) == 0:
            if self.is_done():
                break
            self.start_tasks()
            self.process_all_messages_in_queue()
            finished_tasks_and_results = self.get_finished_results()
        return finished_tasks_and_results
1205208
def process_task(self):
        """"""
        if _debug: ServerSSM._debug("process_task")

        if self.state == SEGMENTED_REQUEST:
            self.segmented_request_timeout()
        elif self.state == AWAIT_RESPONSE:
            self.await_response_timeout()
        elif self.state == SEGMENTED_RESPONSE:
            self.segmented_response_timeout()
        elif self.state == COMPLETED:
            pass
        elif self.state == ABORTED:
            pass
        else:
            if _debug: ServerSSM._debug("invalid state")
            raise RuntimeError("invalid state")
1054111
private void checkTasks() {
    if (currentTask == null) {
      Handler<Task> task = queue.poll();
      if (task != null) {
        currentTask = new Task(this);
        task.handle(currentTask);
      }
    }
  }