示例#1
0
def reserve_worker_pool(self):
    """Reserves pool of workers.

    Called by a tb_coordinator to reserve this pool of workers to do a tree
    expansion. This is accomplished by changing what queue(s) this pool
    listens to.

    Returns:
        str: Name of the new queue the worker pool listens to.
    """
    hostname = self.request.hostname
    private_queue = CORRESPONDING_QUEUE + '_' + hostname
    print('Tried to reserve this worker!')
    print('I am {}'.format(hostname))
    print('Telling myself to ignore the {} and {} queues'.format(
        CORRESPONDING_QUEUE, CORRESPONDING_RESERVABLE_QUEUE))
    from askcos_site.celery import app
    app.control.cancel_consumer(CORRESPONDING_QUEUE, destination=[hostname])
    app.control.cancel_consumer(CORRESPONDING_RESERVABLE_QUEUE,
                                destination=[hostname])

    # *** purge the queue in case old jobs remain
    import celery.bin.amqp
    amqp = celery.bin.amqp.amqp(app=app)
    amqp.run('queue.purge', private_queue)
    print('Telling myself to only listen to the new {} queue'.format(
        private_queue))
    app.control.add_consumer(private_queue, destination=[hostname])
    return private_queue
示例#2
0
    def test_AMQPAdminCommand(self, cls):
        c = cls.return_value = Mock()
        run()
        c.run.assert_called_with()

        x = AMQPAdminCommand(app=self.app)
        x.run()
        self.assertIs(cls.call_args[1]['app'], self.app)
        c.run.assert_called_with()
示例#3
0
    def test_AMQPAdminCommand(self, cls):
        c = cls.return_value = Mock()
        run()
        c.run.assert_called_with()

        x = AMQPAdminCommand(app=self.app)
        x.run()
        self.assertIs(cls.call_args[1]['app'], self.app)
        c.run.assert_called_with()
示例#4
0
 def stop():
     if self.pending_results != []:
         import celery.bin.amqp
         from askcos_site.celery import app
         amqp = celery.bin.amqp.amqp(app=app)
         amqp.run('queue.purge', self.private_worker_queue)
     if self.chiral:
         released = tb_c_worker.unreserve_worker_pool.apply_async(
             queue=self.private_worker_queue, retry=True).get()
     else:
         released = tb_worker.unreserve_worker_pool.apply_async(
             queue=self.private_worker_queue, retry=True).get()
     self.running = False
示例#5
0
 def stop():
     if self.pending_results != []:
         # OPTION 1 - REVOKE TASKS, WHICH GETS SENT TO ALL WORKERS REGARDLESS OF TYPE
         #[res.revoke() for res in pending_results]
         # OPTION 2 - DIRECTLY PURGE THE QUEUE (NOTE: HARDCODED FOR
         # AMQP)
         import celery.bin.amqp
         from askcos_site.celery import app
         amqp = celery.bin.amqp.amqp(app=app)
         amqp.run('queue.purge', self.private_worker_queue)
     if self.chiral and self.private_worker_queue:
         released = tb_c_worker.unreserve_worker_pool.apply_async(
             queue=self.private_worker_queue, retry=True).get()
     elif self.private_worker_queue:
         released = tb_worker.unreserve_worker_pool.apply_async(
             queue=self.private_worker_queue, retry=True).get()
     self.running = False
示例#6
0
 def test_amqp(self, cls):
     c = cls.return_value = Mock()
     run()
     c.run.assert_called_with()
示例#7
0
文件: discard_all.py 项目: ncsa/psync
import psync

# These might work IF the CELERY_ROUTES config setting were set properly
#print( psync.app.control.discard_all() )
#print( psync.app.control.purge() )

# Otherwise, name the queues here
import celery.bin.amqp
amqp = celery.bin.amqp.amqp( app = psync.app )
queuenames = [ 'celery', 'hardlinks', 'directories' ]
for q in queuenames:
    print( 'Queue: ' + q )
    print( amqp.run( 'queue.purge', q ) )
示例#8
0
 def test_amqp(self, cls):
     c = cls.return_value = Mock()
     run()
     c.run.assert_called_with()