From 1a1385dfbac4694b3ab20141e9067d15d3abcc13 Mon Sep 17 00:00:00 2001 From: Vladimir Rychkov Date: Tue, 12 Jul 2016 13:08:17 +0100 Subject: [PATCH 1/2] Guard loop sleep made configurable --- django_q/cluster.py | 4 ++-- django_q/conf.py | 3 +++ docs/configure.rst | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/django_q/cluster.py b/django_q/cluster.py index 877543b..ccdf93f 100644 --- a/django_q/cluster.py +++ b/django_q/cluster.py @@ -208,7 +208,7 @@ class Sentinel(object): logger.info(_('Q Cluster-{} running.').format(self.parent_pid)) scheduler(broker=self.broker) counter = 0 - cycle = 0.5 # guard loop sleep in seconds + cycle = Conf.GUARD_CYCLE # guard loop sleep in seconds # Guard loop. Runs at least once while not self.stop_event.is_set() or not counter: # Check Workers @@ -228,7 +228,7 @@ class Sentinel(object): self.reincarnate(self.pusher) # Call scheduler once a minute (or so) counter += cycle - if counter == 30 and Conf.SCHEDULER: + if counter >= 30 and Conf.SCHEDULER: counter = 0 scheduler(broker=self.broker) # Save current status diff --git a/django_q/conf.py b/django_q/conf.py index f5cb7df..ccf8a5d 100644 --- a/django_q/conf.py +++ b/django_q/conf.py @@ -71,6 +71,9 @@ class Conf(object): # Failures are always saved SAVE_LIMIT = conf.get('save_limit', 250) + # Guard loop sleep in seconds + GUARD_CYCLE = conf.get('guard_cycle', 0.5) + # Disable the scheduler SCHEDULER = conf.get('scheduler', True) diff --git a/docs/configure.rst b/docs/configure.rst index 0de6ff7..73a1c6a 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -78,6 +78,11 @@ Limits the amount of successful tasks saved to Django. - Defaults to ``250`` - Failures are always saved. +guard_cycle +~~~~~~~~~~~ + +Guard loop sleep in seconds + .. _sync: sync From cadbc9f220838778120d0c7d2dab80e4f0d01c46 Mon Sep 17 00:00:00 2001 From: Vladimir Rychkov Date: Wed, 13 Jul 2016 09:44:26 +0100 Subject: [PATCH 2/2] exception raised if guard_cycle configured not in range (0, 60) --- django_q/conf.py | 2 ++ docs/configure.rst | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/django_q/conf.py b/django_q/conf.py index ccf8a5d..dfa719a 100644 --- a/django_q/conf.py +++ b/django_q/conf.py @@ -73,6 +73,8 @@ class Conf(object): # Guard loop sleep in seconds GUARD_CYCLE = conf.get('guard_cycle', 0.5) + if GUARD_CYCLE <= 0 or GUARD_CYCLE >= 60: + raise ValueError('`guard_cycle` must be greater than 0 and less than 60 sec') # Disable the scheduler SCHEDULER = conf.get('scheduler', True) diff --git a/docs/configure.rst b/docs/configure.rst index 73a1c6a..714881a 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -81,7 +81,7 @@ Limits the amount of successful tasks saved to Django. guard_cycle ~~~~~~~~~~~ -Guard loop sleep in seconds +Guard loop sleep in seconds, must be greater than 0 and less than 60. .. _sync: