コード例 #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 suspend_workers_api():
    if request.method == 'POST':
        try:
            suspend(connection=get_current_connection())
        except ActionFailed:
            raise RQMonitorException('Unable to suspend worker/s',
                                     status_code=500)

        return {'message': 'Successfully suspended all workers'}
    raise RQMonitorException('Invalid HTTP Request type', status_code=400)
コード例 #3
0
    def test_suspend_with_duration(self):
        q = Queue()
        for _ in range(5):
            q.enqueue(do_nothing)

        w = Worker([q])

        # This suspends workers for working for 2 second
        suspend(self.testconn, 2)

        # So when this burst of work happens the queue should remain at 5
        w.work(burst=True)
        assert q.count == 5

        sleep(3)

        # The suspension should be expired now, and a burst of work should now clear the queue
        w.work(burst=True)
        assert q.count == 0
コード例 #4
0
ファイル: worker.py プロジェクト: produvia/kryptos
    def shutdown_job(self):
        self.logger.warning("Suspending worker connection")
        suspend(self.connection)
        job = self.get_current_job()
        if job is None:
            self.logger.info("No current job, killing worker process")
            return os.kill(os.getpid(), signal.SIGRTMIN)

        self.logger.warning("Initiating job cleanup")
        self.logger.warning(f"Attempting requeue current job {job.id}")
        self.logger.warning("quarantining job")
        fq = get_failed_queue()
        fq.quarantine(job, exc_info="Graceful shutdown")

        self.logger.info("Setting job as PAUSED")
        job.meta["PAUSED"] = True
        job.save()
        self.logger.warning(f"Moving job {job.id} back to queue")
        fq.requeue(job.id)
        self.logger.warning("Gracefully requeued job")
        self.logger.warning(
            "Sending SIGRTMIN to own process to kill self and job")
        # job.kill()  # causes algo to exit gracefully
        os.kill(os.getpid(), signal.SIGRTMIN)
コード例 #5
0
ファイル: bp.py プロジェクト: eyecat/rqmonitor
def suspend_workers_api():
    if request.method == 'POST':
        suspend(connection=get_current_connection())
        return {'message': 'Successfully suspended all workers'}
コード例 #6
0
def suspend():
    suspension.suspend(conn)