def _select_queue(is_batch: bool, request_high_priority: bool) -> rq.Queue: """ Return a queue. Return the batch queue iff is_batch is True. Otherwise return the high queue if request_high_priority is True and return the low queue otherwise. """ if is_batch: return rq.Queue("batch", connection=redis_connection()) elif request_high_priority: return rq.Queue("high", connection=redis_connection()) else: return rq.Queue("low", connection=redis_connection())
def next_port(): """ Return a port number that is greater than the last time this method was called (by any process on this machine). This port number is not guaranteed to be free """ r = redis_connection() return int(r.incr(REDIS_PORT_INT) or 0) % (PORT_MAX - PORT_MIN) + PORT_MIN
def _get_queue(**kw): """ Return a queue. The returned queue is one whose condition function returns True when called with the arguments in **kw. """ for queue in config["queues"]: if form_validation.is_valid(kw, queue["schema"]): return rq.Queue(queue["name"], connection=redis_connection()) raise InvalidQueueError( "cannot enqueue job: unable to determine correct queue type" )
def cancel_tests(client_type: str, client_data: Dict, test_data: List[Dict]) -> None: """ Cancel a test run job with enqueued with the same """ with rq.Connection(redis_connection()): for data in test_data: client = get_client(client_type, {**client_data, **data}) try: job = rq.job.Job.fetch(client.unique_run_str()) except NoSuchJobError: continue if job.is_queued(): job.cancel()
def cancel_test(markus_address, run_ids, **_kw): """ Cancel a test run job with the job_id defined using markus_address and run_id. """ with rq.Connection(redis_connection()): for run_id in run_ids: job_id = _format_job_id(markus_address, run_id) try: job = rq.job.Job.fetch(job_id) except NoSuchJobError: return if job.is_queued(): files_path = job.kwargs["files_path"] if files_path: shutil.rmtree(files_path, onerror=ignore_missing_dir_error) job.cancel()
def test_gets_new_connection(self, conn, clear_rq_connection): """ Create new connection object from config settings if None exists """ rm.redis_connection() assert call(config["redis", "url"]).call_list() == conn.mock_calls
def test_gets_existing_redis_connection(self, _conn, clear_rq_connection): """ Reuse previous connection object """ assert rm.redis_connection() == rm.redis_connection()