Skip to content

Commit

Permalink
Reduce worker idle queries
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasst committed Feb 16, 2021
1 parent 6d96607 commit 5d9afc3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tasktiger/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ def _filter_queues(self, queues):
)
]

def _worker_perform_secondary_tasks(self):
# We should queue scheduled tasks every QUEUE_SCHEDULED_TASKS_TIME time
# and expired tasks every REQUEUE_EXPIRED_TASKS_INTERVAL time. Use only
# one Redis query to enter this block since every single worker calls
# this every second.
# XXX: Ideally, we should keep track of workers and take turns.
key = self._key("lock", "secondary_tasks")
# if self.connection.set(key, "1", ex=1, nx=True):
if True:
self._worker_queue_scheduled_tasks()
self._worker_queue_expired_tasks()

def _worker_queue_scheduled_tasks(self):
"""
Helper method that takes due tasks from the SCHEDULED queue and puts
Expand Down Expand Up @@ -1046,8 +1058,7 @@ def _worker_run(self):
time.time() - self._last_task_check > self.config['SELECT_TIMEOUT']
and not self._stop_requested
):
self._worker_queue_scheduled_tasks()
self._worker_queue_expired_tasks()
self._worker_perform_secondary_tasks()
self._last_task_check = time.time()

def _queue_periodic_tasks(self):
Expand Down

0 comments on commit 5d9afc3

Please sign in to comment.