当前位置: 首页>>代码示例>>Python>>正文


Python Worker.create方法代码示例

本文整理汇总了Python中pq.worker.Worker.create方法的典型用法代码示例。如果您正苦于以下问题:Python Worker.create方法的具体用法?Python Worker.create怎么用?Python Worker.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pq.worker.Worker的用法示例。


在下文中一共展示了Worker.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
 def setUp(self):
     self.q = Queue()
     self.w = Worker.create(
         [self.q],
         expires_after=1,
         default_worker_ttl=1
     )
开发者ID:oinopion,项目名称:django-pq,代码行数:9,代码来源:test_worker.py

示例2: handle

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
    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
        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 = list(map(Queue.create, args))
        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(args.sentry_dsn)
            register_sentry(client, w)

        w.work(burst=options['burst'])
开发者ID:vladignatyev,项目名称:django-pq,代码行数:29,代码来源:pqworker.py

示例3: handle

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
    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 = []
        if options.get('terminate'):
            workern = [w.name for w in Worker.objects.all()]

            for worker in Worker.objects.all()[:]:
                worker.stop = True
                worker.save()

            print('Terminating %s ...' % ' '.join(workern))  
            while Worker.objects.all():
                time.sleep(5)
            
            return
        if not args:
            args = [q[0] for q in Queue.objects.values_list('name').exclude(name='failed')]
            args.sort()
        if not args:
            print('There are no queues to work on')
            sys.exit(1)
        for queue in args:
            try:
                q = Queue.objects.get(name=queue)
            except Queue.DoesNotExist:
                print("The '%s' queue does not exist. Use the pqcreate command to create it." % queue)
                continue
            if q.serial:
                q = SerialQueue.objects.get(name=queue)
            else:
                q = Queue.objects.get(name=queue)
            q.connection = options['connection']
            q._saved = True
            queues.append(q)
        if queues:
            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'])
开发者ID:JirkaV,项目名称:django-pq,代码行数:60,代码来源:pqworker.py

示例4: setUp

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
 def setUp(self):
     q = Queue()
     q.enqueue(say_hello, kwargs={'name':'bob'}, result_ttl=1)  # expires
     q.enqueue(say_hello, kwargs={'name':'polly'})  # won't expire in this test lifecycle
     q.enqueue(say_hello, kwargs={'name':'frank'}, result_ttl=-1) # never expires
     w = Worker.create([q])
     w.work(burst=True)
     q.enqueue(say_hello, kwargs={'name':'david'}) # hasn't run yet
     self.q = q
开发者ID:vladignatyev,项目名称:django-pq,代码行数:11,代码来源:test_queue.py

示例5: setUp

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
 def setUp(self):
     password = "test"
     user = User.objects.create_superuser("test", "[email protected]", password)
     self.client.login(username=user.username, password=password)
     self.q = Queue()
     self.q.enqueue_call(say_hello, args=("you",))
     self.q.enqueue_call(div_by_zero, args=(1,))
     w = Worker.create(self.q)
     w.work(burst=True)
     self.q.enqueue_call(say_hello, args=("me",))
开发者ID:vladignatyev,项目名称:django-pq,代码行数:12,代码来源:test_admin.py

示例6: setUp

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
 def setUp(self):
     password = 'test'
     user = User.objects.create_superuser('test', '[email protected]', password)
     self.client.login(username=user.username, password=password)
     self.q = Queue()
     self.q.enqueue_call(say_hello, args=('you',))
     self.q.enqueue_call(div_by_zero, args=(1,))
     self.q.schedule(datetime(2099, 1, 1, tzinfo=utc), say_hello, 'later')
     w = Worker.create(self.q)
     w.work(burst=True)
     self.q.enqueue_call(say_hello, args=('me',))
开发者ID:oinopion,项目名称:django-pq,代码行数:13,代码来源:test_admin.py

示例7: test_custom_exc_handling

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
    def test_custom_exc_handling(self):
        """Custom exception handling."""

        w = Worker.create([self.q], exc_handler=self.black_hole)
        w.work(burst=True)  # should silently pass

        # Postconditions
        self.assertEqual(self.q.count, 0)
        self.assertEqual(self.fq.count, 0)

        # Check the job
        job = Job.objects.get(id=self.job.id)
        self.assertEqual(job.status, Job.FAILED)
开发者ID:oinopion,项目名称:django-pq,代码行数:15,代码来源:test_worker.py

示例8: test_create_worker

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
    def test_create_worker(self):
        """Worker creation."""

        w = Worker.create([self.fooq, self.barq])
        self.assertEquals(w.queues, [self.fooq, self.barq])
开发者ID:vilos,项目名称:django-pq,代码行数:7,代码来源:test_worker.py

示例9: setUp

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
 def setUp(self):
     self.q = Queue()
     self.fq = get_failed_queue()
     self.w = Worker.create([self.q])
     self.job = self.q.enqueue(div_by_zero)
     self.enqueued_at = self.job.enqueued_at
开发者ID:vilos,项目名称:django-pq,代码行数:8,代码来源:test_worker.py

示例10: setUp

# 需要导入模块: from pq.worker import Worker [as 别名]
# 或者: from pq.worker.Worker import create [as 别名]
 def setUp(self):
     self.q = Queue(scheduled=True)
     self.w = Worker.create([self.q])
开发者ID:oinopion,项目名称:django-pq,代码行数:5,代码来源:test_queue.py


注:本文中的pq.worker.Worker.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。