def test_suspend_worker_execution(self): """Test Pause Worker Execution""" SENTINEL_FILE = '/tmp/rq-tests.txt' try: # Remove the sentinel if it is leftover from a previous test run os.remove(SENTINEL_FILE) except OSError as e: if e.errno != 2: raise q = Queue() q.enqueue(create_file, SENTINEL_FILE) w = Worker([q]) suspend(self.testconn) w.work(burst=True) assert q.count == 1 # Should not have created evidence of execution self.assertEqual(os.path.exists(SENTINEL_FILE), False) resume(self.testconn) w.work(burst=True) assert q.count == 0 self.assertEqual(os.path.exists(SENTINEL_FILE), True)
def resume_workers_api(): if request.method == 'POST': try: resume(connection=get_current_connection()) except ActionFailed: raise RQMonitorException('Unable to resume worker/s', status_code=500) return {'message': 'Successfully resumed all workers'} raise RQMonitorException('Invalid HTTP Request type', status_code=400)
def manage_workers(): log.info(f"Starting core service in {CONFIG_ENV} env") log.debug(f"Using Redis connection {REDIS_HOST}:{REDIS_PORT}") remove_zombie_workers() # remove_stale_workers() # start main worker with Connection(CONN): if is_suspended(CONN): log.info("Resuming connection for startup") resume(CONN) requeue_terminated_fail_jobs() log.info("Starting initial workers") log.debug("Starting worker for BACKTEST queue") spawn_worker("backtest") log.debug("Starting worker for PAPER queues") spawn_worker("paper") log.debug("Starting worker for LIVE queues") spawn_worker("live") log.debug("Starting worker for TA queue") spawn_worker("ta") # create paper/live queues when needed while not is_suspended(CONN): for q in QUEUE_NAMES: required = workers_required(q) for i in range(required): spawn_worker(q, burst=True) time.sleep(5) time.sleep(2) else: log.warning("Instance is shutting down")
def resume_workers_api(): if request.method == 'POST': resume(connection=get_current_connection()) return {'message': 'Successfully resumed all workers'}
def resume(): suspension.resume(conn)