Beispiel #1
0
    def bk_done(self,
                brid: RPCKey,
                jid: RPCKey,
                ok: bool,
                res: Optional[ResponseType] = None):
        w = service(Worker[self.cls_req, self.cls_res], sender())
        w.done_ack(brid, jid)

        if self._brid_check(brid):
            return

        if jid not in self.jobs:
            trc('1').error('%s', jid)
            return

        if self.jobs[jid].finished:
            trc('2').warning('%s', jid)
            return

        if jid in self.jobs_pending_assign:
            del self.jobs_pending_assign[jid]

        if jid in self.jobs_pending_resign:
            del self.jobs_pending_resign[jid]

        if jid not in self.jobs_workers or sender() != self.jobs_workers[jid]:
            return

        self._worker_pings(brid, sender())

        if ok:
            self._job_done(jid, res)
        else:
            self._job_resign(jid)
Beispiel #2
0
    def bk_assign(self, brid: RPCKey, jid: RPCKey, ok: bool):
        sdr = sender()
        if sdr not in self.workers:
            trc('3').error('%s', sdr)
            return

        if self._brid_check(brid):
            return

        if jid not in self.jobs:
            trc('1').error('%s', jid)
            return

        if jid not in self.jobs_workers:
            trc('2').error('%s', jid)
            return

        if jid not in self.workers_jobs[sdr]:
            trc('5').error('%s', jid)
            return

        if jid in self.jobs_pending_assign:
            del self.jobs_pending_assign[jid]

        self._worker_pings(brid, sdr)

        if ok:
            return
        else:
            if jid in self.jobs_pending_resign:
                del self.jobs_pending_resign[jid]

            self._job_resign(jid)
Beispiel #3
0
    def bk_announce(self, is_fork: bool, wpid: int):
        sdr = sender()

        trc('0').error('%s %s %s', sdr, is_fork, wpid)

        if is_fork:
            if sdr in self.workers_fork_addrs:
                return
            else:
                self.workers_fork_addrs[sdr] = wpid

                s = service(WorkerForkInst, sdr, group=BACKEND)

                for _ in range(self.par_conf.threads):
                    trc('01').error('%s', _)
                    s.fork()
            return

        if sdr in self.worker_addrs:
            return

        trc('1').debug('%s', sdr)

        self.worker_addrs[sdr] = wpid
        self.workers_free.push(sdr)
        self.load.capacity += 1

        if self.load.capacity == self.par_conf.processes * self.par_conf.threads:
            trc('capa').debug('capacity reached')
            self._started()

        if self.has_started:
            self.push_announce()
Beispiel #4
0
    def bk_announce(self, wbrid: Optional[RPCKey], load: WorkerLoad):
        wid = sender()

        trc('1').debug('%s', wid)

        if wid not in self.workers:
            self._worker_new(RPCKey.new(), wid, load)

        brid = self.workers_brids[wid]

        if wbrid != brid:
            s = service(Worker[self.cls_req, self.cls_res], wid,
                        ClientConfig(timeout_total=1))
            s.registered(self.workers_brids[wid])

        # todo only ping workers through announce

        wst = self.workers[wid]

        flag_changed = wst.load.capacity != load.capacity

        wst.load.capacity = load.capacity
        self._worker_pings(brid, wid)

        if flag_changed:
            self._worker_conf_changed()
Beispiel #5
0
    def bk_register(self, load: WorkerLoad) -> Optional[RPCKey]:
        wid = sender()

        if wid in self.workers:
            # a worker needs to be unregistered first
            return None

        wbrid = RPCKey.new()

        self._worker_new(wbrid, wid, load)
Beispiel #6
0
    def bk_done(self, res: ResponseType):
        wid = sender()

        if wid not in self.workers_jobs:
            trc('1').error('%s', wid)
            return

        jid = self.workers_jobs[wid]

        if jid not in self.jobs_workers:
            trc('1').error('%s', jid)
            return

        self.jobs_res[jid] = res
        self.jobs_pending_done.push(SchedKey(time_now(), jid))
        reset(self.push_done, 0)

        wid = self.jobs_workers[jid]
        del self.jobs_workers[jid]
        del self.workers_jobs[wid]

        self.load.occupied -= 1
        self.workers_free.push(wid)
Beispiel #7
0
    def arrived(self):
        sdr = sender()
        self.origins[sdr] = 5

        if sdr not in self.origins_met:
            self.origins_met.add(sdr)
Beispiel #8
0
 def _brid_check(self, brid: RPCKey):
     wid = sender()
     if self.workers_brids.get(wid) != brid:
         trc('brid', depth=2).error('%s', brid)
         return True
     return False
Beispiel #9
0
 def _finished_ack(jid: RPCKey):
     s = service(BrokerFlushAck, sender(), group=DEFAULT_GROUP)
     s.flush_ack(jid)
Beispiel #10
0
 def bk_started(self):
     self.thread_addr = sender()
     reset(self.check_started, None)
     reset(self.announce, 0)
Beispiel #11
0
 def fork(self):
     trc('0').error('%s', sender())
     if os.fork() == 0:
         context().actor.get('signal')._fork_transport_patch()
         raise ForkException()
Beispiel #12
0
    def bk_unregister(self):
        wid = sender()

        if wid in self.workers:
            self._worker_lost(wid)
Beispiel #13
0
    def count_status(self, name: str = 'running') -> int:
        s = service(RecursiveA, sender(),
                    ClientConfig(timeout_total=1., horz=False))

        return len([x for x in s.status() if x == name])
Beispiel #14
0
 def _ack(self, jid: RPCKey):
     s = service(Broker[Request, Response], sender(), group=DEFAULT_GROUP)
     s: Broker[Request, Response]
     s.flush_ack(jid)