def process_active_list(self): """ Process all currently running tasks. """ log.info("active_queue = " + str(self.active_queue.qsize())) i = random.randint(0, 5) while i > 0: self.add_work("TEST_TASK", core.worker.test_task, random.randint(0, 30)) i -= 1
def run(self): """ Start worker. """ log.info("worker started") while True: task_name, _callable, args, kwds = self.task_queue.get() log.debug("worker got " + task_name) # pylint: disable-msg=W0142 results = _callable(*args, **kwds) # pylint: enable-msg=W0142 if results is False: log.error("Task failed: " + task_name)
def run(self): """ Check the tasks queue and run anything that is due. """ while True: while self.current_workers < self.total_workers: log.debug("worker added") core.worker.Worker(self.active_queue) self.current_workers += 1 self.process_pending_list() self.process_active_list() self.process_done_list() log.info("active_queue = " + str(self.active_queue.qsize())) time.sleep(core.config.TIMER_SLEEP_INTERVAL) log.debug("waking")
Start threads. """ import sys import time import core.config import core.timer from core.log import mylogger as log import core.db import core.worker PROGNAME = 'Monrito' VERSION = '0.0.16' log.info(PROGNAME + ' version ' + VERSION + ' starting') log.info('Starting Database: ') DB = core.db.start_database() if DB: log.info('Database started') else: log.critical('Database failed to initalize - aborting') sys.exit(1) log.info('Starting Timer: ') TM = core.timer.Timer() if TM: log.info('Timer started') else: log.critical('Timer failed to initalize - aborting')
def process_done_list(self): """ Finish any tasks that have completed. """ log.info("done_queue = " + str(self.done_queue.qsize()))
def process_pending_list(self): """ Process all pending tasks. """ log.info("pending_queue = " + str(self.pending_queue.qsize()))