Ejemplo n.º 1
0
 def __init__(self,
              exchange,
              topic,
              tasks,
              executor=None,
              threads_count=None,
              url=None,
              transport=None,
              transport_options=None,
              retry_options=None):
     self._topic = topic
     self._executor = executor
     self._owns_executor = False
     self._threads_count = -1
     if self._executor is None:
         if threads_count is not None:
             self._threads_count = int(threads_count)
         else:
             self._threads_count = tu.get_optimal_thread_count()
         self._executor = futures.ThreadPoolExecutor(self._threads_count)
         self._owns_executor = True
     self._endpoints = self._derive_endpoints(tasks)
     self._exchange = exchange
     self._server = server.Server(topic,
                                  exchange,
                                  self._executor,
                                  self._endpoints,
                                  url=url,
                                  transport=transport,
                                  transport_options=transport_options,
                                  retry_options=retry_options)
Ejemplo n.º 2
0
 def __init__(self,
              exchange,
              topic,
              tasks,
              executor=None,
              threads_count=None,
              url=None,
              transport=None,
              transport_options=None,
              retry_options=None):
     self._topic = topic
     self._executor = executor
     self._owns_executor = False
     if self._executor is None:
         self._executor = futurist.ThreadPoolExecutor(
             max_workers=threads_count)
         self._owns_executor = True
     self._endpoints = self._derive_endpoints(tasks)
     self._exchange = exchange
     self._server = server.Server(topic,
                                  exchange,
                                  self._executor,
                                  self._endpoints,
                                  url=url,
                                  transport=transport,
                                  transport_options=transport_options,
                                  retry_options=retry_options)
Ejemplo n.º 3
0
 def __init__(self, exchange, topic, tasks, executor=None, **kwargs):
     self._topic = topic
     self._executor = executor
     self._threads_count = kwargs.pop('threads_count',
                                      tu.get_optimal_thread_count())
     if self._executor is None:
         self._executor = futures.ThreadPoolExecutor(self._threads_count)
     self._endpoints = self._derive_endpoints(tasks)
     self._server = server.Server(topic, exchange, self._executor,
                                  self._endpoints, **kwargs)
Ejemplo n.º 4
0
 def server(self, reset_master_mock=False, **kwargs):
     server_kwargs = dict(topic=self.server_topic,
                          exchange=self.server_exchange,
                          executor=self.executor_mock,
                          endpoints=self.endpoints,
                          url=self.broker_url)
     server_kwargs.update(kwargs)
     s = server.Server(**server_kwargs)
     if reset_master_mock:
         self.resetMasterMock()
     return s
Ejemplo n.º 5
0
 def _fetch_server(self, task_classes):
     endpoints = []
     for cls in task_classes:
         endpoints.append(endpoint.Endpoint(cls))
     server = worker_server.Server(TEST_TOPIC,
                                   TEST_EXCHANGE,
                                   futures.ThreadPoolExecutor(1),
                                   endpoints,
                                   transport='memory',
                                   transport_options={
                                       'polling_interval': POLLING_INTERVAL,
                                   })
     server_thread = threading_utils.daemon_thread(server.start)
     return (server, server_thread)
Ejemplo n.º 6
0
 def __init__(self, exchange, topic, tasks, executor=None, **kwargs):
     self._topic = topic
     self._executor = executor
     self._owns_executor = False
     self._threads_count = -1
     if self._executor is None:
         if 'threads_count' in kwargs:
             self._threads_count = int(kwargs.pop('threads_count'))
             if self._threads_count <= 0:
                 raise ValueError("threads_count provided must be > 0")
         else:
             self._threads_count = tu.get_optimal_thread_count()
         self._executor = futures.ThreadPoolExecutor(self._threads_count)
         self._owns_executor = True
     self._endpoints = self._derive_endpoints(tasks)
     self._exchange = exchange
     self._server = server.Server(topic, exchange, self._executor,
                                  self._endpoints, **kwargs)