Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

implemented #2 - option '--foreground' for synchronous job submission

  • Loading branch information...
commit 284f76b400c092d7b199d4b551c86160a2ab0953 1 parent 94a1036
@jsk jsk authored
1  README.rst
@@ -189,6 +189,7 @@ You can submit first job easily with 'gearman_submit_job' commands::
Job submission done, result: <GearmanJobRequest task='data_import', unique='8e610a031cef8aaf50c30f451d77808d', priority=None, background=True, state='CREATED', timed_out=False>.
By default, jobs are submitted in background and 'gearman_submit_job' does not wait for job to finish.
+You can override this with '--foreground' CLI option. See './ gearman_submit_job --help'.
If you did everything right, your worker method 'your_code_performing_job_logic()' should be now running in background.
This method is fine if you want to run job manually or from cron.
17 django_gearman_commands/management/commands/
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
import logging
+from optparse import make_option
import gearman
from import BaseCommand, CommandError
import django_gearman_commands.settings
from django_gearman_commands import get_namespace
@@ -15,6 +13,13 @@
class Command(BaseCommand):
"""Submit specific gearman job with job data as an arguments."""
+ option_list = BaseCommand.option_list + (
+ make_option("--foreground",
+ action="store_true",
+ dest="foreground",
+ default=False,
+ help="Wait until task is completed. False by default, tasks are sent to background."),
+ )
args = '<task_name> [job_data]'
help = 'Submit gearman job with specified task, optionally with job data'
@@ -33,8 +38,10 @@ def handle(self, *args, **options):
self.stdout.write('Submitting job: {0:s}, job data: {1:s}.\n'.format(task_name, job_data if job_data else '(empty)'))
client = gearman.GearmanClient(django_gearman_commands.settings.GEARMAN_SERVERS)
- result = client.submit_job(task_name, job_data, wait_until_complete=options.get('wait_until_complete', False),
- background=options.get('background', True))
+ is_foreground = options.get('foreground', True)
+ result = client.submit_job(task_name, job_data,
+ wait_until_complete=True if is_foreground else False,
+ background=False if is_foreground else True)
self.stdout.write('Job submission done, result: {0:s}.\n'.format(result))

0 comments on commit 284f76b

Please sign in to comment.
Something went wrong with that request. Please try again.