本文整理汇总了Python中pq.worker.Worker类的典型用法代码示例。如果您正苦于以下问题:Python Worker类的具体用法?Python Worker怎么用?Python Worker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Worker类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.q = Queue()
self.w = Worker.create(
[self.q],
expires_after=1,
default_worker_ttl=1
)
示例2: handle
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'])
示例3: handle
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'])
示例4: setUp
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
示例5: setUp
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",))
示例6: setUp
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',))
示例7: test_custom_exc_handling
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)
示例8: test_create_worker
def test_create_worker(self):
"""Worker creation."""
w = Worker.create([self.fooq, self.barq])
self.assertEquals(w.queues, [self.fooq, self.barq])
示例9: setUp
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
示例10: setUp
def setUp(self):
self.q = Queue(scheduled=True)
self.w = Worker.create([self.q])