Please name this parameter "exchange_store", so it matches the name of the expected type (ExchangeStore) and it is shorter. Also, now that we have it, the ExchangeStore could be used to store also other types of information beside MessageContext's, so it makes sense to use a generic name for it.
+ self._store = message_context_store
Similarly please name this attribute "self._exchange_store", to make it clear which store is referring to (there is another attribute called "self._message_store", so the naming will be consistent).
[10]
+ else:
+ if "timestamp" not in message:
+ message["timestamp"] = int(self._reactor.time())
+ message_id = self._message_store.add(message)
+ if urgent:
+ self.schedule_exchange(urgent=True)
+ return message_id
I think you can save this else/indentation level and simply write:
+ if "timestamp" not in message:
+ message["timestamp"] = int(self._reactor.time())
+ message_id = self._message_store.add(message)
+ if urgent:
+ self.schedule_exchange(urgent=True)
+ return message_id
I personally like the pattern when you check a series of early-return conditions, before reaching the meat of a function/method, like
if this:
return something
if that:
return something_else
[9]
+ message_ context_ store,
Please name this parameter "exchange_store", so it matches the name of the expected type (ExchangeStore) and it is shorter. Also, now that we have it, the ExchangeStore could be used to store also other types of information beside MessageContext's, so it makes sense to use a generic name for it.
+ self._store = message_ context_ store
Similarly please name this attribute "self._ exchange_ store", to make it clear which store is referring to (there is another attribute called "self._ message_ store", so the naming will be consistent).
[10]
+ else: "timestamp" ] = int(self. _reactor. time()) store.add( message) exchange( urgent= True)
+ if "timestamp" not in message:
+ message[
+ message_id = self._message_
+ if urgent:
+ self.schedule_
+ return message_id
I think you can save this else/indentation level and simply write:
+ if "timestamp" not in message: "timestamp" ] = int(self. _reactor. time()) store.add( message) exchange( urgent= True)
+ message[
+ message_id = self._message_
+ if urgent:
+ self.schedule_
+ return message_id
I personally like the pattern when you check a series of early-return conditions, before reaching the meat of a function/method, like
if this:
return something
if that:
return something_else
do_the_actual_thing
[11]
+ exchange_store = ExchangeStore( join(config. data_path, "exchange. database" ))
+ os.path.
Just to avoid hard-coding this value you could add a property to l.broker. config. BrokerConfigura tion, like:
@property store_path( self): join(self. data_path, "exchange. database" ))
def exchange_
return os.path.
and use it as
+ exchange_store = ExchangeStore( self.config. exchange_ store_path)
[12]
+ exchange_store = ExchangeStore( join(test_ case.config. data_path, "exchange. database" ))
+ os.path.
Please add this object to the test_case attributes, so it can be used in tests:
+ test_case. exchange_ store = ExchangeStore( join(test_ case.config. data_path, "exchange. database" ))
+ os.path.
after that you can avoid creating it explicitly in all the tests.
[13]
+ self.exchanger. _store. get_message_ context( message[ 'operation- id']))
Once you have self.exchange_store as test attribute (see [12]) you should use it instead of accessing this private attribute.
Thanks!