Skip to content

Commit

Permalink
Add WORKER_FUNC_MODIFIER feature
Browse files Browse the repository at this point in the history
  • Loading branch information
JereMalinen committed Mar 18, 2019
1 parent c84fd11 commit ab5a3da
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions django_q/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,16 @@ def worker(task_queue, result_queue, timer, timeout=Conf.TIMEOUT):
result = (e, False)
if error_reporter:
error_reporter.report()
if Conf.WORKER_FUNC_MODIFIER:
try:
module, func = f.rsplit('.', 1)
m = importlib.import_module(module)
modifier = getattr(m, func)
f = modifier(f)
except (ValueError, ImportError, AttributeError) as e:
result = (e, False)
if error_reporter:
error_reporter.report()
# We're still going
if not result:
db.close_old_connections()
Expand Down
2 changes: 2 additions & 0 deletions django_q/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class Conf(object):
# Option to undaemonize the workers and allow them to spawn child processes
DAEMONIZE_WORKERS = conf.get('daemonize_workers', True)

WORKER_FUNC_MODIFIER = conf.get('worker_func_modifier', None)

# Maximum number of tasks that each cluster can work on
QUEUE_LIMIT = conf.get('queue_limit', int(WORKERS) ** 2)

Expand Down

0 comments on commit ab5a3da

Please sign in to comment.