示例#1
0
    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)
示例#2
0
文件: bp.py 项目: trodery/rqmonitor
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)
示例#3
0
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")
示例#4
0
文件: bp.py 项目: eyecat/rqmonitor
def resume_workers_api():
    if request.method == 'POST':
        resume(connection=get_current_connection())
        return {'message': 'Successfully resumed all workers'}
示例#5
0
def resume():
    suspension.resume(conn)