1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Adds rq retry options (#12588)

* adds rq retry options #12327

* Clean up docs; disable retries of failed jobs by default

* Pass a Retry object only if RQ_RETRY_MAX is non-zero

---------

Co-authored-by: jeremystretch <jstretch@netboxlabs.com>
This commit is contained in:
Abhimanyu Saharan
2023-05-16 11:10:44 -07:00
committed by GitHub
parent 0df6a5793a
commit 2204735e9f
5 changed files with 43 additions and 4 deletions

View File

@ -1,11 +1,12 @@
from django_rq.queues import get_connection
from rq import Worker
from rq import Retry, Worker
from netbox.config import get_config
from netbox.constants import RQ_QUEUE_DEFAULT
__all__ = (
'get_queue_for_model',
'get_rq_retry',
'get_workers_for_queue',
)
@ -22,3 +23,14 @@ def get_workers_for_queue(queue_name):
Returns True if a worker process is currently servicing the specified queue.
"""
return Worker.count(get_connection(queue_name))
def get_rq_retry():
"""
If RQ_RETRY_MAX is defined and greater than zero, instantiate and return a Retry object to be
used when queuing a job. Otherwise, return None.
"""
retry_max = get_config().RQ_RETRY_MAX
retry_interval = get_config().RQ_RETRY_INTERVAL
if retry_max:
return Retry(max=retry_max, interval=retry_interval)