def send_headers(self, force=False): if not self._headers_sent: tosend = self.get_headers(force) if tosend: events.fire('http-headers', self, headers=tosend) self._headers_sent = tosend.flat(self.version, self.status) return self._headers_sent
def fire(result, app): if not is_failure(result): result = app else: result.log() events.fire(name, app) app.events[name].callback(app)
def exit(self, result=None): '''Exit from the :class:`Actor` domain.''' if not self.stopped(): # we don't want monitors to stop the request loop if not self.is_monitor(): self.requestloop.stop() self.mailbox.close() self.state = ACTOR_STATES.CLOSE self.logger.debug('%s exited', self) remove_actor(self) events.fire('exit', self) self.on_exit()
def start(self): '''Called after forking to start the actor's life. This is where logging is configured, the :attr:`Actor.mailbox` is registered and the :attr:`Actor.ioloop` is initialised and started.''' if self.state == ACTOR_STATES.INITIAL: self.configure_logging() self._setup_ioloop() events.fire('start', self) self.on_start() self.periodic_task() self.state = ACTOR_STATES.RUN self._run()
def stop(self, force=False, exit_code=None): '''Stop the actor by stopping its :attr:`Actor.requestloop` and closing its :attr:`Actor.mailbox`. Once everything is closed properly this actor will go out of scope.''' if force or self.state <= ACTOR_STATES.RUN: events.fire('stop', self) self.state = ACTOR_STATES.STOPPING self.exit_code = exit_code try: res = self.on_stop() except: self.logger.error('Unhandle error while stopping', exc_info=True) res = None return res.addBoth(self.exit) if is_async(res) else self.exit()
def monitor_start(self, monitor): # When the monitor starts load all :class:`TestRequest` into the # in the :attr:`pulsar.Actor.ioqueue`. loader = self.local.loader tags = self.cfg.labels try: self.local.tests = tests = list(loader.testclasses(tags)) if tests: self.logger.info('loaded %s test classes', len(tests)) self.runner.on_start() events.fire('tests', self, tests=tests) monitor.cfg.set('workers', min(self.cfg.workers, len(tests))) self._time_start = None else: raise ExitTest('Could not find any tests.') except ExitTest as e: print(str(e)) monitor.arbiter.stop() except Exception: LOGGER.critical('Error occurred before starting tests', exc_info=True) monitor.arbiter.stop()
def __call__(self, actor=None): if actor is None: actor = get_actor() monitor = None if actor and actor.is_arbiter(): monitor = actor.monitors.get(self.name) if monitor is None and (not actor or actor.is_arbiter()): # Add events self.local.events = dict(app_events(self)) self.cfg.on_start() self.configure_logging() events.fire('ready', self) arbiter = pulsar.arbiter(cfg=self.cfg.new_config()) if self.on_config() is not False: monitor = arbiter.add_monitor(ApplicationMonitor, self.name, app=self, cfg=self.cfg, ioqueue=self.ioqueue) self.cfg = monitor.cfg if self.commands_set: monitor.impl.commands_set.update(self.commands_set) if self.events: return self.events['start']