Exemple #1
0
 def handle(self, *args, **options):
     """
     The actual logic of the command. Subclasses must implement
     this method.
     """
     from pq.queue import Queue, SerialQueue
     verbosity = int(options.get('verbosity', 1))
     func = args[0]
     args = args[1:]
     async = not options.get('sync')
     timeout = options.get('timeout')
     queue = options.get('queue')
     conn = options.get('conn')
     if options['serial']:
         queue = queue or 'serial'
         q = SerialQueue.create(queue, connection=conn)
     else:
         queue = queue or 'default'
         q = Queue.create(queue, connection=conn)
     if timeout:
         job = q.enqueue_call(func, args=args, timeout=timeout, async=async)
     else:
         job = q.enqueue_call(func, args=args, async=async)
     if verbosity and job.id:
         print('Job %i created' % job.id)
     elif verbosity:
         print('Job complete')
Exemple #2
0
    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.

        """
        from django.conf import settings
        from pq.queue import Queue, SerialQueue
        from pq.worker import Worker

        sentry_dsn = options.get('sentry_dsn')
        if not sentry_dsn:
            sentry_dsn = settings.SENTRY_DSN if hasattr(settings, 'SENTRY_DSN') else None

        verbosity = int(options.get('verbosity'))
        queues = []
        for queue in args:
            q = Queue.objects.get(name=queue)
            if q.serial:
                queues.append(SerialQueue.create(name=queue))
            else:
                queues.append(Queue.create(name=queue))
        w = Worker.create(queues, name=options.get('name'), connection=options['connection'])

        # Should we configure Sentry?
        if sentry_dsn:
            from raven import Client
            from pq.contrib.sentry import register_sentry
            client = Client(sentry_dsn)
            register_sentry(client, w)

        w.work(burst=options['burst'])
Exemple #3
0
    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.
        """
        from pq.queue import Queue, SerialQueue

        verbosity = int(options.get('verbosity', 1))
        func = args[0]
        args = args[1:]
        async = not options.get('sync')
        timeout = options.get('timeout')
        queue = options.get('queue')
        conn = options.get('conn')
        if options['serial']:
            queue = queue or 'serial'
            q = SerialQueue.create(queue, connection=conn)
        else:
            queue = queue or 'default'
            q = Queue.create(queue, connection=conn)
        if timeout:
            job = q.enqueue_call(func, args=args, timeout=timeout, async=async)
        else:
            job = q.enqueue_call(func, args=args, async=async)
        if verbosity and job.id:
            print('Job %i created' % job.id)
        elif verbosity:
            print('Job complete')
Exemple #4
0
    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.
        """
        from pq.queue import Queue, SerialQueue

        verbosity = int(options.get('verbosity', 1))
        func = args[1]
        if args[0].lower() == 'now':
            at = now()
        else:
            at = parser.parse(args[0])
        if not at.tzinfo:
            at = at.replace(tzinfo=get_default_timezone())

        args = args[2:]
        if options.get('mtwtf'):
            weekdays = (0, 1, 2, 3, 4)
        else:
            weekdays = (
                options.get('mo'),
                options.get('tu'),
                options.get('we'),
                options.get('th'),
                options.get('fr'),
                options.get('sa'),
                options.get('su'),
            )

            weekdays = [w for w in weekdays if isinstance(w, integer_types)]
        timeout = options.get('timeout')
        queue = options.get('queue')
        conn = options.get('conn')
        if options['serial']:
            queue = queue or 'serial'
            q = SerialQueue.create(queue, connection=conn, scheduled=True)
        else:
            queue = queue or 'default'
            q = Queue.create(queue, connection=conn, scheduled=True)
        job = q.schedule_call(
            at, func,
            args=args,
            timeout=timeout,
            repeat=options['repeat'],
            interval=options['interval'],
            between=options['between'],
            weekdays=weekdays
        )
        if verbosity:
            print('Job %i created' % job.id)
Exemple #5
0
    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.
        """
        from pq.queue import Queue, SerialQueue
        verbosity = int(options.get('verbosity', 1))
        func = args[1]
        if args[0].lower() == 'now':
            at = now()
        else:
            at = parser.parse(args[0])
        if not at.tzinfo:
            at = at.replace(tzinfo=get_default_timezone())

        args = args[2:]
        if options.get('mtwtf'):
            weekdays = (0,1,2,3,4)
        else:
            weekdays = (
                options.get('mo'),
                options.get('tu'),
                options.get('we'),
                options.get('th'),
                options.get('fr'),
                options.get('sa'),
                options.get('su'),
                )

            weekdays = [w for w in weekdays if isinstance(w, integer_types)]
        timeout = options.get('timeout')
        queue = options.get('queue')
        conn = options.get('conn')
        if options['serial']:
            queue = queue or 'serial'
            q = SerialQueue.create(queue, connection=conn, scheduled=True)
        else:
            queue = queue or 'default'
            q = Queue.create(queue, connection=conn, scheduled=True)
        job = q.schedule_call(at, func, args=args, 
            timeout=timeout,
            repeat=options['repeat'],
            interval=options['interval'],
            between=options['between'],
            weekdays=weekdays
            )
        if verbosity:
            print('Job %i created' % job.id)
Exemple #6
0
 def handle(self, *args, **options):
     """
     The actual logic of the command. Subclasses must implement
     this method.
     """
     from pq.queue import Queue, SerialQueue
     verbosity = int(options.get('verbosity', 1))
     timeout = options.get('timeout')
     for queue in args:
         if options['serial']:
             q = SerialQueue.create(queue)
         else:
             q = Queue.create(queue)
         q.connection = options.get('conn')
         q.scheduled = options.get('scheduled')
         if timeout:
             q.default_timeout = timeout
         q.save()
Exemple #7
0
 def handle(self, *args, **options):
     """
     The actual logic of the command. Subclasses must implement
     this method.
     """
     from pq.queue import Queue, SerialQueue
     verbosity = int(options.get('verbosity', 1))
     timeout = options.get('timeout')
     for queue in args:
         if options['serial']:
             q = SerialQueue.create(queue)
         else:
             q = Queue.create(queue)
         q.connection = options.get('conn')
         q.scheduled = options.get('scheduled')
         if timeout:
             q.default_timeout = timeout
         q.save()
Exemple #8
0
    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.
        """
        from pq.queue import Queue, SerialQueue

        func = args[1]
        if args[0].lower() == 'now':
            at = now()
        else:
            at = parser.parse(args[0])
        if not at.tzinfo:
            at = at.replace(tzinfo=get_default_timezone())

        args = args[2:]
        if options.get('mtwtf'):
            weekdays = (0,1,2,3,4)
        else:
            weekdays = (
                options.get('mo'),
                options.get('tu'),
                options.get('we'),
                options.get('th'),
                options.get('fr'),
                options.get('sa'),
                options.get('su'),
                )
            weekdays = [w for w in weekdays if w]
        timeout = options.get('timeout')
        queue = options.get('queue')
        if options['serial']:
            queue = queue or 'serial'
            q = SerialQueue.create(queue)
        else:
            queue = queue or 'default'
            q = Queue.create(queue)
        q.schedule_call(at, func, args=args, 
            timeout=timeout,
            repeat=options['repeat'],
            interval=options['interval'],
            between=options['between'],
            weekdays=weekdays
            )
Exemple #9
0
    def handle(self, *args, **options):
        """
        The actual logic of the command. Subclasses must implement
        this method.
        """
        from pq.queue import Queue, SerialQueue

        func = args[0]
        args = args[1:]
        timeout = options.get("timeout")
        queue = options.get("queue")
        if options["serial"]:
            queue = queue or "serial"
            q = SerialQueue.create(queue)
        else:
            queue = queue or "default"
            q = Queue.create(queue)
        if timeout:
            q.enqueue(func, *args, timeout=timeout)
        else:
            q.enqueue(func, *args)
Exemple #10
0
 def setUp(self):
     self.q = SerialQueue.create()
     self.assertTrue(self.q.serial)
 def setUp(self):
     self.sq = SerialQueue.create()
     self.job = self.sq.enqueue(do_nothing)
     self.sq.acquire_lock(1)
 def setUp(self):
     self.sq = SerialQueue.create()
Exemple #13
0
 def test_default_queue_create_multiple(self):
     queue = Queue.create()
     self.assertEqual(queue.name, 'default')
     queue = SerialQueue.create()
     self.assertEqual(queue.name, 'default (serial)')
Exemple #14
0
 def test_serial_queue_create(self):
     sq = SerialQueue.create()
     self.assertTrue(sq.serial)
 def test_serial_queue_create(self):
     sq = SerialQueue.create()
     self.assertTrue(sq.serial)
 def test_default_queue_create_multiple(self):
     queue = Queue.create()
     self.assertEqual(queue.name, 'default')
     queue = SerialQueue.create()
     self.assertEqual(queue.name, 'default (serial)')
Exemple #17
0
 def setUp(self):
     self.sq = SerialQueue.create()
 def setUp(self):
     self.sq = SerialQueue.create()
     self.sq.acquire_lock(1)
Exemple #19
0
 def setUp(self):
     self.sq = SerialQueue.create()
     self.sq.acquire_lock(1)
 def setUp(self):
     self.q = SerialQueue.create()
     self.assertTrue(self.q.serial)
Exemple #21
0
 def setUp(self):
     self.sq = SerialQueue.create()
     self.job = self.sq.enqueue(do_nothing)
     self.sq.acquire_lock(1)