Process all messages in the `status_queue` and check for any batches that needs to change status

        Returns:
            `None`
19157
def process_status_queue(self):
        
        self.log.debug('Start processing status queue')
        while True:
            messages = self.status_queue.receive_messages(MaxNumberOfMessages=10)

            if not messages:
                break

            for message in messages:
                data = json.loads(message.body)
                job = SchedulerJob.get(data['id'])
                try:
                    if job and job.update_status(data['status']):
                        db.session.commit()
                except SchedulerError as ex:
                    if hasattr(ex, 'message') and ex.message == 'Attempting to update already completed job':
                        pass

                message.delete()

        # Close any batch that is now complete
        open_batches = db.SchedulerBatch.find(SchedulerBatch.status < SchedulerStatus.COMPLETED)
        for batch in open_batches:
            open_jobs = list(filter(lambda x: x.status < SchedulerStatus.COMPLETED, batch.jobs))
            if not open_jobs:
                open_batches.remove(batch)
                batch.update_status(SchedulerStatus.COMPLETED)
                self.log.debug('Closed completed batch {}'.format(batch.batch_id))
            else:
                started_jobs = list(filter(lambda x: x.status > SchedulerStatus.PENDING, open_jobs))
                if batch.status == SchedulerStatus.PENDING and len(started_jobs) > 0:
                    batch.update_status(SchedulerStatus.STARTED)
                    self.log.debug('Started batch manually {}'.format(batch.batch_id))

        # Check for stale batches / jobs
        for batch in open_batches:
            if batch.started < datetime.now() - timedelta(hours=2):
                self.log.warning('Closing a stale scheduler batch: {}'.format(batch.batch_id))
                for job in batch.jobs:
                    if job.status < SchedulerStatus.COMPLETED:
                        job.update_status(SchedulerStatus.ABORTED)
                batch.update_status(SchedulerStatus.ABORTED)
        db.session.commit()
1195055
def update_status(self, callback_function_param=False):
        
        self.logger.debug("Receiver:Updating status")
        self.send_message({MESSAGE_TYPE: TYPE_GET_STATUS},
                          callback_function=callback_function_param)
1037510
def on_status_update(self, channel, callback):
        
        if channel not in self._callbacks:
            self._callbacks[channel] = []
        self._callbacks[channel].append(callback)
725065
def process_single_message_from_queue(self):
        
        try:
            message = self.message_queue.get_nowait()
            task_id, data = message
            task = self.task_id_to_task[task_id]
            task.on_message(data)
            return True
        except queue.Empty:
            return False
39550
def manage_finished_checks(self, queue):
        
        to_del = []
        wait_time = 1.0
        now = time.time()
        logger.debug("--- manage finished checks")
        for action in self.checks:
            logger.debug("--- checking: last poll: %s, now: %s, wait_time: %s, action: %s",
                         action.last_poll, now, action.wait_time, action)
            if action.status == ACT_STATUS_LAUNCHED and action.last_poll < now - action.wait_time:
                action.check_finished(self.max_plugins_output_length)
                wait_time = min(wait_time, action.wait_time)
            # If action done, we can launch a new one
            if action.status in [ACT_STATUS_DONE, ACT_STATUS_TIMEOUT]:
                logger.debug("--- check done/timeout: %s", action.uuid)
                self.actions_finished += 1
                to_del.append(action)
                # We answer to our master
                try:
                    msg = Message(_type='Done', data=action, source=self._id)
                    logger.debug("Queuing message: %s", msg)
                    queue.put_nowait(msg)
                except Exception as exp:  # pylint: disable=broad-except
                    logger.error("Failed putting messages in returns queue: %s", str(exp))

        for chk in to_del:
            logger.debug("--- delete check: %s", chk.uuid)
            self.checks.remove(chk)

        # Little sleep
        logger.debug("--- manage finished checks terminated, I will wait: %s", wait_time)
        time.sleep(wait_time)
155319
def _check_queue(queue, kwargs):
    '''
    
    '''
    if queue:
        _wait(kwargs.get('__pub_jid'))
    else:
        conflict = running(concurrent=kwargs.get('concurrent', False))
        if conflict:
            __context__['retcode'] = 1
            return conflict
131886
def _flush(self):
        
        # Send a None down the queue to indicate a flush
        try:
            self.queue.put(None, block=False)
        except Queue.Full:
            self._throttle_error('Queue full, check handlers for delays')
484230
def run(self):
        
        while True:
            msg = self._queue.get()
            if msg is _SHUTDOWN:
                break
            event, args, kwargs = msg
            self._logger('<< %s', event)
            for func in self._callbacks.get(event, []):
                func(*args, **kwargs)
1155591
def output_callback(self, out, process_status):
        
        self.final_status.append(process_status)
        self.final_output.append(out)
733460
def start_message_processing(self):
        
        t = InfiniteLoopThread(self.process_messages, thread_name="MESSAGEPROCESSOR", wait_between_runs=0.5)
        t.start()
        return t
405221
def process_events
      until @dead
        @mutex.synchronize do
          while @queue.empty?
            break if @dead
            @not_empty.wait(@mutex)
          end
          event = @queue.pop
          break unless event
          notify_listeners(event)
          event.dispatch
        end
      end
    rescue Exception => ex
      Logger.error "Error while running event: #{Logger.format_error(ex)}"
    end
1279873
protected void processQueue() {
        try {
            Collection<RequestMetric> batch = new ArrayList<>(this.batchSize);
            RequestMetric rm = queue.take();
            batch.add(rm);
			queue.drainTo(batch, this.batchSize - 1);
			
			Builder builder = new Bulk.Builder();
			for (RequestMetric metric : batch) {
	            Index index = new Index.Builder(metric).refresh(false)
	                    .index(getIndexName())
	                    .type("request").build(); //$NON-NLS-1$
				builder.addAction(index);
			}
            
            BulkResult result = getClient().execute(builder.build());
            if (!result.isSucceeded()) {
                logger.warn("Failed to add metric(s) to ES"); //$NON-NLS-1$
            }
        } catch (Exception e) {
            logger.warn("Error adding metric to ES"); //$NON-NLS-1$
            return;
        }
    }
1226467
def process_next_message(self, timeout):
        """"""
        message = self.worker_manager.receive(timeout)

        if isinstance(message, Acknowledgement):
            self.task_manager.task_start(message.task, message.worker)
        elif isinstance(message, Result):
            self.task_manager.task_done(message.task, message.result)
776168
async def _process_message(self, message):
        
        self._pending_ack.add(message.msg_id)
        handler = self._handlers.get(message.obj.CONSTRUCTOR_ID,
                                     self._handle_update)
        await handler(message)
202467
def process_messages_loop_internal(self):
        
        while self.receiving_messages:
            # connect to AMQP server and listen for 1 message then disconnect
            self.work_request = None
            self.connection.receive_loop_with_callback(self.queue_name, self.save_work_request_and_close)
            if self.work_request:
                self.process_work_request()
1109368
def _update_observers(self, batch_id, status):
        
        for observer, statuses in self._observers.copy().items():
            if batch_id in statuses:
                statuses[batch_id] = status
                if self._has_no_pendings(statuses):
                    observer.notify_batches_finished(statuses)
                    self._observers.pop(observer)
1105384
def batch!(request, request_options = {})
      res = batch(request, request_options)
      wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, request_options)
      res
    end