Skip to content

Commit

Permalink
Merge pull request #19 from dabapps/no-multiprocessing
Browse files Browse the repository at this point in the history
Revert "Use multiprocessing to run tasks in child processes"
  • Loading branch information
Pete Wildsmith committed Apr 26, 2016
2 parents 09893a6 + 759eb00 commit 81533a8
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions django_dbq/management/commands/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from simplesignals.process import WorkerProcessBase
from time import sleep
import logging
import multiprocessing


logger = logging.getLogger(__name__)
Expand All @@ -15,8 +14,18 @@
DEFAULT_QUEUE_NAME = 'default'


def run_next_task(job):
"""Updates a job by running its next task"""
def process_job(queue_name):
"""This function grabs the next available job for a given queue, and runs its next task."""

with transaction.atomic():
job = Job.objects.get_ready_or_none(queue_name)
if not job:
return

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)
job.state = Job.STATES.PROCESSING
job.save()

try:
task_function = import_by_path(job.next_task)
task_function(job)
Expand Down Expand Up @@ -46,23 +55,6 @@ def run_next_task(job):
raise


def process_job(queue_name):
"""This function grabs the next available job for a given queue, and runs its next task."""

with transaction.atomic():
job = Job.objects.get_ready_or_none(queue_name)
if not job:
return

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)
job.state = Job.STATES.PROCESSING
job.save()

child = multiprocessing.Process(target=run_next_task, args=(job,))
child.start()
child.join()


class Worker(WorkerProcessBase):

process_title = "jobworker"
Expand Down

0 comments on commit 81533a8

Please sign in to comment.