Esempio n. 1
0
            def run_all(self):
                procs = []
                if not self.workers:
                    log.error("No workers are configured in the specified context")

                for worker in self.workers:
                    proc = spawn(worker.run, context)
                    procs.append(proc)
                waitall(procs)
Esempio n. 2
0
    def run(self):
        try:
            with self.context:
                self._listener = self._start_listener()
                self._dispatcher = spawn(self.run_dispatcher)

            procs = [self._listener, self._dispatcher]
            waitall(procs)
        except GreenletExit:
            pass
        finally:
            killall(procs)
            waitall(procs)
Esempio n. 3
0
def run_aggregator(context):
    try:
        worker_pool = Pool()

        @pooled(worker_pool)
        @always_ack
        def bucket_modified_handler(message_data, message):
            try:
                with context:
                    _handle_bucket_modified(message_data, message, context)
            except GreenletExit:
                pass
            except: 
                log.error("Unexpected error handling bucking modified message: %s" % traceback.format_exc())

        
        @pooled(worker_pool)
        @always_ack
        def update_subscription_handler(message_data, message):
            try:
                with context:
                    _handle_update_subscription(message_data, message, context)
            except GreenletExit:
                pass
            except: 
                log.error("Unexpected error handling update subscription message: %s" % traceback.format_exc())

        procs = []
        with context:
            dispatcher = MessageDispatch(context)
            procs.append(dispatcher.start_worker(BUCKET_MODIFIED, bucket_modified_handler))
            procs.append(dispatcher.start_worker(UPDATE_SUBSCRIPTION, update_subscription_handler))
    
        waitall(procs)
    except GreenletExit:
        pass
    except: 
        log.error("Unexpected error running aggregator process: %s" % traceback.format_exc())
    finally:
        # stop accepting work
        killall(procs)
        waitall(procs)
        # stop working on existing work
        worker_pool.killall()
        worker_pool.waitall()
Esempio n. 4
0
 def kill(self):
     for p in self._procs.values():
         p.kill()
     waitall(self._procs.values())