Facebook
From Ample Elephant, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 82
  1. import os
  2. import time
  3. from notifier_modules import PublisherO2MQ, Publisher
  4.  
  5.  
  6. class ClientITRO2MQ(PublisherO2MQ):
  7.     def __init__(self, process_params):
  8.         super().__init__(process_params)
  9.  
  10.     def client_set_type_metadata_file(self):
  11.         self.trigger_settings["type_metadata_file"] = ".csv"
  12.  
  13.     def client_set_unique_field(self):
  14.         self.trigger_settings["unique_field"] = "Cheque Number"
  15.  
  16.  
  17. class ContextMapException(Exception):
  18.     pass
  19.  
  20.  
  21. class ContextMap:
  22.     def __init__(self, process_params):
  23.         self.process_params = process_params
  24.  
  25.     @property
  26.     def client(self):
  27.         return self.process_params["client"]
  28.  
  29.     @property
  30.     def rule(self):
  31.         return self.process_params["rule"]
  32.  
  33.     @property
  34.     def client_key(self):
  35.         return (self.client + "_" + self.rule).lower()
  36.  
  37.     @property
  38.     def context_map(self):
  39.         if "itr_itr" in self.client_key:
  40.             return "O2MQ", ClientITRO2MQ
  41.  
  42.         else:
  43.             raise ContextMapException(
  44.                 f"internal error, cannot match client_key {self.client_key}"
  45.             )
  46.  
  47.  
  48. class PubisherLauncher:
  49.     def __init__(self, context_map, client_name):
  50.         self.context_map = context_map
  51.         self.client_name = client_name
  52.         self.__run()
  53.  
  54.     def __run(self):
  55.         while True:
  56.             with Publisher(self.context_map, self.client_name) as p:
  57.                 sleep_time = 0.3 if os.environ["ENV"] == "dev" else 2
  58.                 time.sleep(sleep_time)
  59.  
  60.  
  61. if __name__ == "__main__":
  62.     PubisherLauncher(ContextMap, "itr")
  63.