예제 #1
0
 def slc_init(self):
     queue_name = self.spawn_args["queue_name_work"]
     self.workReceiver = WorkerReceiver(name=queue_name,
                                        label=__name__,
                                        scope=WorkerReceiver.SCOPE_SYSTEM,
                                        handler=self.receive)
     self.queue_name_work = self.workReceiver.xname
     extradict = {"queue_name_work": self.queue_name_work}
     cei_events.event("worker", "init_begin", extra=extradict)
     self.laterinitialized = False
     reactor.callLater(0, self.later_init)
예제 #2
0
파일: epu_worker.py 프로젝트: timf/epu
 def slc_init(self):
     queue_name = self.spawn_args["queue_name_work"]
     self.workReceiver = WorkerReceiver(name=queue_name,
                                        label=__name__,
                                        scope=WorkerReceiver.SCOPE_SYSTEM,
                                        handler=self.receive)
     self.queue_name_work = self.workReceiver.xname
     extradict = {"queue_name_work":self.queue_name_work}
     cei_events.event("worker", "init_begin", extra=extradict)
     self.laterinitialized = False
     reactor.callLater(0, self.later_init)
예제 #3
0
class EPUWorkerService(ServiceProcess):
    """EPU Worker service.
    """
    declare = ServiceProcess.service_declare(name='epu_worker',
                                             version='0.1.0',
                                             dependencies=[])

    def slc_init(self):
        queue_name = self.spawn_args["queue_name_work"]
        self.workReceiver = WorkerReceiver(name=queue_name,
                                           label=__name__,
                                           scope=WorkerReceiver.SCOPE_SYSTEM,
                                           handler=self.receive)
        self.queue_name_work = self.workReceiver.xname
        extradict = {"queue_name_work": self.queue_name_work}
        cei_events.event("worker", "init_begin", extra=extradict)
        self.laterinitialized = False
        reactor.callLater(0, self.later_init)

    @defer.inlineCallbacks
    def later_init(self):
        spawnId = yield self.workReceiver.attach()
        log.debug("spawnId: %s" % spawnId)
        self.laterinitialized = True
        extradict = {"queue_name_work": self.queue_name_work}
        cei_events.event("worker", "init_end", extra=extradict)

    @defer.inlineCallbacks
    def op_work(self, content, headers, msg):
        if not self.laterinitialized:
            log.error("message got here without the later-init")
        sleepsecs = int(content['work_amount'])
        extradict = {
            "batchid": content['batchid'],
            "jobid": content['jobid'],
            "work_amount": sleepsecs
        }
        cei_events.event("worker", "job_begin", extra=extradict)
        log.info("WORK: sleeping for %d seconds ---" % sleepsecs)
        yield pu.asleep(sleepsecs)
        yield self.reply(msg, 'result', {'result': 'work_complete'}, {})
        cei_events.event("worker", "job_end", extra=extradict)
예제 #4
0
파일: epu_worker.py 프로젝트: timf/epu
class EPUWorkerService(ServiceProcess):
    """EPU Worker service.
    """
    declare = ServiceProcess.service_declare(name='epu_worker', version='0.1.0', dependencies=[])

    def slc_init(self):
        queue_name = self.spawn_args["queue_name_work"]
        self.workReceiver = WorkerReceiver(name=queue_name,
                                           label=__name__,
                                           scope=WorkerReceiver.SCOPE_SYSTEM,
                                           handler=self.receive)
        self.queue_name_work = self.workReceiver.xname
        extradict = {"queue_name_work":self.queue_name_work}
        cei_events.event("worker", "init_begin", extra=extradict)
        self.laterinitialized = False
        reactor.callLater(0, self.later_init)

    @defer.inlineCallbacks
    def later_init(self):
        spawnId = yield self.workReceiver.attach()
        log.debug("spawnId: %s" % spawnId)
        self.laterinitialized = True
        extradict = {"queue_name_work":self.queue_name_work}
        cei_events.event("worker", "init_end", extra=extradict)

    @defer.inlineCallbacks
    def op_work(self, content, headers, msg):
        if not self.laterinitialized:
            log.error("message got here without the later-init")
        sleepsecs = int(content['work_amount'])
        extradict = {"batchid":content['batchid'],
                     "jobid":content['jobid'],
                     "work_amount":sleepsecs}
        cei_events.event("worker", "job_begin", extra=extradict)
        log.info("WORK: sleeping for %d seconds ---" % sleepsecs)
        yield pu.asleep(sleepsecs)
        yield self.reply(msg, 'result', {'result':'work_complete'}, {})
        cei_events.event("worker", "job_end", extra=extradict)