Debian Codegraph @

django_rq/management/commands/rqenqueue.py

raw
1 from django.core.management.base import BaseCommand
2
3 from ... import get_queue
4
5
6 class Command(BaseCommand):
7 """
8 Queue a function with the given arguments.
9 """
10
11 help = __doc__
12 args = '<function arg arg ...>'
13
14 def add_arguments(self, parser):
15 parser.add_argument('--queue', '-q', dest='queue', default='default', help='Specify the queue [default]')
16 parser.add_argument('--timeout', '-t', type=int, dest='timeout', help='A timeout in seconds')
17 parser.add_argument('args', nargs='*')
18
19 def handle(self, *args, **options):
20 """
21 Queues the function given with the first argument with the
22 parameters given with the rest of the argument list.
23 """
24 queue = get_queue(options['queue'])
25 job = queue.enqueue_call(args[0], args=args[1:], timeout=options['timeout'])
26 if options['verbosity']:
27 print(f'Job {job.id} created')