def _test_loop(self): class ConnectionStub: exits = False def clean_up(self): self.exits = True connection_stub = ConnectionStub() properties = {DEVICE_GROUP : "test"} task_broker = TaskBroker(connection_stub, properties) #Case where no stop file and keep_looping_true class ChannelStub: wait_called = False def wait(self): self.wait_called = True task_broker._keep_looping = False channel_stub = ChannelStub() task_broker._connection.channel = channel_stub task_broker._loop() self.assertTrue(channel_stub.wait_called) #Case where keep_looping False task_broker._keep_looping = False task_broker._loop() self.assertTrue(connection_stub.exits) #Case where stop_file_exists connection_stub.exits = False task_broker._keep_looping = True def _stop_file_exists(): return True task_broker._stop_file_exists = _stop_file_exists task_broker._loop() self.assertTrue(connection_stub.exits)
def _task_broker_factory(dispatch_func = None): connection = Connection(vhost = "/", host = "localhost", port = 5672, username = "******", password = "******") connection.connect() task_broker = TaskBroker(connection, _get_properties()) if dispatch_func: task_broker._dispatch = dispatch_func task_broker._init_connection() return task_broker
def _task_broker_factory(dispatch_func=None): connection = Connection(vhost="/", host="localhost", port=5672, username="******", password="******") connection.connect() task_broker = TaskBroker(connection, _get_properties()) if dispatch_func: task_broker._dispatch = dispatch_func task_broker._init_connection() return task_broker
class Worker(object): """ Worker class """ def __init__(self, vhost, host, port, username, password, properties, device_n=0): """ Initialise the class, read config, set up logging """ self._vhost = vhost self._host = host self._port = port self._username = username self._password = password self._properties = properties self._timeout = None self._device_n = device_n self.log = get_logger_adapter(__name__) ########################### # AMQP Log Handler ########################### def start(self): """ Starts the ots worker server running """ self.log.info('Initialising the server') # If stop flag is there, remove it if os.path.exists(STOP_SIGNAL_FILE): os.system("rm -fr "+STOP_SIGNAL_FILE) self._connection = Connection(self._vhost, self._host, self._port, self._username, self._password) self._task_broker = TaskBroker(self._connection, self._properties) self.log.info("Starting the worker " + \ "%d. server: %s:%s, device_properties: %s" % (self._device_n, self._host, self._port, self._properties)) self._task_broker.run()
class Worker(object): """ Worker class """ def __init__(self, vhost, host, port, username, password, properties, device_n=0): """ Initialise the class, read config, set up logging """ self._vhost = vhost self._host = host self._port = port self._username = username self._password = password self._properties = properties self._timeout = None self._device_n = device_n self.log = get_logger_adapter(__name__) ########################### # AMQP Log Handler ########################### def start(self): """ Starts the ots worker server running """ self.log.info('Initialising the server') # If stop flag is there, remove it if os.path.exists(STOP_SIGNAL_FILE): os.system("rm -fr " + STOP_SIGNAL_FILE) self._connection = Connection(self._vhost, self._host, self._port, self._username, self._password) self._task_broker = TaskBroker(self._connection, self._properties) self.log.info("Starting the worker " + \ "%d. server: %s:%s, device_properties: %s" % (self._device_n, self._host, self._port, self._properties)) self._task_broker.run()
def start(self): """ Starts the ots worker server running """ self.log.info('Initialising the server') # If stop flag is there, remove it if os.path.exists(STOP_SIGNAL_FILE): os.system("rm -fr " + STOP_SIGNAL_FILE) self._connection = Connection(self._vhost, self._host, self._port, self._username, self._password) self._task_broker = TaskBroker(self._connection, self._properties) self.log.info("Starting the worker " + \ "%d. server: %s:%s, device_properties: %s" % (self._device_n, self._host, self._port, self._properties)) self._task_broker.run()
def start(self): """ Starts the ots worker server running """ self.log.info('Initialising the server') # If stop flag is there, remove it if os.path.exists(STOP_SIGNAL_FILE): os.system("rm -fr "+STOP_SIGNAL_FILE) self._connection = Connection(self._vhost, self._host, self._port, self._username, self._password) self._task_broker = TaskBroker(self._connection, self._properties) self.log.info("Starting the worker " + \ "%d. server: %s:%s, device_properties: %s" % (self._device_n, self._host, self._port, self._properties)) self._task_broker.run()
def _test_loop(self): class ConnectionStub: exits = False def clean_up(self): self.exits = True connection_stub = ConnectionStub() properties = {DEVICE_GROUP: "test"} task_broker = TaskBroker(connection_stub, properties) #Case where no stop file and keep_looping_true class ChannelStub: wait_called = False def wait(self): self.wait_called = True task_broker._keep_looping = False channel_stub = ChannelStub() task_broker._connection.channel = channel_stub task_broker._loop() self.assertTrue(channel_stub.wait_called) #Case where keep_looping False task_broker._keep_looping = False task_broker._loop() self.assertTrue(connection_stub.exits) #Case where stop_file_exists connection_stub.exits = False task_broker._keep_looping = True def _stop_file_exists(): return True task_broker._stop_file_exists = _stop_file_exists task_broker._loop() self.assertTrue(connection_stub.exits)