Skip to content

Commit 81533a8

Browse files
author
Pete Wildsmith
committed
Merge pull request #19 from dabapps/no-multiprocessing
Revert "Use multiprocessing to run tasks in child processes"
2 parents 09893a6 + 759eb00 commit 81533a8

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

django_dbq/management/commands/worker.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from simplesignals.process import WorkerProcessBase
77
from time import sleep
88
import logging
9-
import multiprocessing
109

1110

1211
logger = logging.getLogger(__name__)
@@ -15,8 +14,18 @@
1514
DEFAULT_QUEUE_NAME = 'default'
1615

1716

18-
def run_next_task(job):
19-
"""Updates a job by running its next task"""
17+
def process_job(queue_name):
18+
"""This function grabs the next available job for a given queue, and runs its next task."""
19+
20+
with transaction.atomic():
21+
job = Job.objects.get_ready_or_none(queue_name)
22+
if not job:
23+
return
24+
25+
logger.info('Processing job: name="%s" queue="%s" id=%s state=%s next_task=%s', job.name, queue_name, job.pk, job.state, job.next_task)
26+
job.state = Job.STATES.PROCESSING
27+
job.save()
28+
2029
try:
2130
task_function = import_by_path(job.next_task)
2231
task_function(job)
@@ -46,23 +55,6 @@ def run_next_task(job):
4655
raise
4756

4857

49-
def process_job(queue_name):
50-
"""This function grabs the next available job for a given queue, and runs its next task."""
51-
52-
with transaction.atomic():
53-
job = Job.objects.get_ready_or_none(queue_name)
54-
if not job:
55-
return
56-
57-
logger.info('Processing job: name="%s" queue="%s" id=%s state=%s next_task=%s', job.name, queue_name, job.pk, job.state, job.next_task)
58-
job.state = Job.STATES.PROCESSING
59-
job.save()
60-
61-
child = multiprocessing.Process(target=run_next_task, args=(job,))
62-
child.start()
63-
child.join()
64-
65-
6658
class Worker(WorkerProcessBase):
6759

6860
process_title = "jobworker"

0 commit comments

Comments
 (0)