From af3b1da08f79b3b6a7820b2c34a9efe3ea5495fc Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Tue, 26 Jan 2016 22:29:00 +0100 Subject: [PATCH 1/2] Makes DB polling time configurable via `poll` setting --- django_q/brokers/mongo.py | 2 +- django_q/brokers/orm.py | 2 +- django_q/conf.py | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/django_q/brokers/mongo.py b/django_q/brokers/mongo.py index dfce5ba..a1235e7 100644 --- a/django_q/brokers/mongo.py +++ b/django_q/brokers/mongo.py @@ -61,7 +61,7 @@ class Mongo(Broker): if task: return [(str(task['_id']), task['payload'])] # empty queue, spare the cpu - sleep(0.2) + sleep(Conf.POLL) def delete_queue(self): return self.collection.drop() diff --git a/django_q/brokers/orm.py b/django_q/brokers/orm.py index 0e65863..a0db3a9 100644 --- a/django_q/brokers/orm.py +++ b/django_q/brokers/orm.py @@ -61,7 +61,7 @@ class ORM(Broker): task_list.append((task.pk, task.payload)) return task_list # empty queue, spare the cpu - sleep(0.2) + sleep(Conf.POLL) def delete_queue(self): return self.purge_queue() diff --git a/django_q/conf.py b/django_q/conf.py index ae8d022..58989d4 100644 --- a/django_q/conf.py +++ b/django_q/conf.py @@ -50,6 +50,9 @@ class Conf(object): # ORM broker ORM = conf.get('orm', None) + # Database Poll + POLL = conf.get('poll', 0.2) + # MongoDB broker MONGO = conf.get('mongo', None) MONGO_DB = conf.get('mongo_db', None) From ddb8f8117fd43c4040dabc8e0855419640ad18f4 Mon Sep 17 00:00:00 2001 From: Ilan Steemers Date: Tue, 26 Jan 2016 22:49:29 +0100 Subject: [PATCH 2/2] docs: adds `poll` configuration option --- docs/configure.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/configure.rst b/docs/configure.rst index cb0183d..56453e5 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -303,6 +303,11 @@ Keep in mind however that settings this too high can degrade performance with mu Not supported by the default Redis broker. Defaults to ``1``. +poll +~~~~ +Sets the queue polling interval for database brokers that don't have a blocking call. Defaults to 0.2 (seconds). +Currently only affects the ORM and MongoDB brokers. + cache ~~~~~ For some brokers, you will need to set up the Django `cache framework `__