def __init__(self, uuid, exchange, topics, transition_timeout=pr.REQUEST_TIMEOUT, url=None, transport=None, transport_options=None, retry_options=None): self._uuid = uuid self._requests_cache = wt.RequestsCache() self._transition_timeout = transition_timeout type_handlers = { pr.RESPONSE: dispatcher.Handler(self._process_response, validator=pr.Response.validate), } self._proxy = proxy.Proxy(uuid, exchange, type_handlers=type_handlers, on_wait=self._on_wait, url=url, transport=transport, transport_options=transport_options, retry_options=retry_options) # NOTE(harlowja): This is the most simplest finder impl. that # doesn't have external dependencies (outside of what this engine # already requires); it though does create periodic 'polling' traffic # to workers to 'learn' of the tasks they can perform (and requires # pre-existing knowledge of the topics those workers are on to gather # and update this information). self._finder = wt.ProxyWorkerFinder(uuid, self._proxy, topics) self._finder.notifier.register(wt.WorkerFinder.WORKER_ARRIVED, self._on_worker) self._helpers = tu.ThreadBundle() self._helpers.bind(lambda: tu.daemon_thread(self._proxy.start), after_start=lambda t: self._proxy.wait(), before_join=lambda t: self._proxy.stop()) p_worker = periodics.PeriodicWorker.create([self._finder]) if p_worker: self._helpers.bind(lambda: tu.daemon_thread(p_worker.start), before_join=lambda t: p_worker.stop(), after_join=lambda t: p_worker.reset(), before_start=lambda t: p_worker.reset())
def __init__(self, uuid, exchange, topics, transition_timeout=pr.REQUEST_TIMEOUT, url=None, transport=None, transport_options=None, retry_options=None): self._uuid = uuid self._topics = topics self._requests_cache = wt.RequestsCache() self._workers = wt.TopicWorkers() self._transition_timeout = transition_timeout type_handlers = { pr.NOTIFY: [ self._process_notify, functools.partial(pr.Notify.validate, response=True), ], pr.RESPONSE: [ self._process_response, pr.Response.validate, ], } self._proxy = proxy.Proxy(uuid, exchange, type_handlers, on_wait=self._on_wait, url=url, transport=transport, transport_options=transport_options, retry_options=retry_options) self._periodic = wt.PeriodicWorker(tt.Timeout(pr.NOTIFY_PERIOD), [self._notify_topics]) self._helpers = tu.ThreadBundle() self._helpers.bind(lambda: tu.daemon_thread(self._proxy.start), after_start=lambda t: self._proxy.wait(), before_join=lambda t: self._proxy.stop()) self._helpers.bind(lambda: tu.daemon_thread(self._periodic.start), before_join=lambda t: self._periodic.stop(), after_join=lambda t: self._periodic.reset(), before_start=lambda t: self._periodic.reset())
def setUp(self): super(TestThreadBundle, self).setUp() self.bundle = tu.ThreadBundle() self.death = tu.Event() self.addCleanup(self.bundle.stop) self.addCleanup(self.death.set)