| Total Complexity | 3 |
| Total Lines | 26 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | 1 | import os |
|
| 9 | 1 | class QueueManager(): |
|
| 10 | 1 | def __init__(self, config_file: str, listener: str): |
|
| 11 | """Init the Queue from config parameters""" |
||
| 12 | |||
| 13 | 1 | base_path = os.path.abspath(os.path.dirname(__file__)) |
|
| 14 | 1 | config_specs = base_path + '/static/specs.yml' |
|
| 15 | 1 | config_default = base_path + '/static/default.yml' |
|
| 16 | |||
| 17 | 1 | config = ConfigReader().parse(config_file, config_specs, config_default) |
|
| 18 | 1 | config_listener = config.get('distributer') |
|
| 19 | |||
| 20 | 1 | redis = Redis(config_listener['host'], config_listener['port']) |
|
| 21 | |||
| 22 | 1 | if listener not in config: |
|
| 23 | 1 | raise KeyError('You must have a key {} in your config with a sub-key queue'.format(listener)) |
|
| 24 | |||
| 25 | 1 | self._logger = Logger('distributer', config_file) |
|
| 26 | 1 | self._logger.log.debug('Distributer QueueManager called') |
|
| 27 | 1 | self._logger.log.debug('Connect to queue {}'.format(config[listener]['queue'])) |
|
| 28 | 1 | self._queue = RedisQueue(config[listener]['queue'], connection=redis) |
|
| 29 | |||
| 30 | |||
| 31 | 1 | def add(self, method: str, item: str, job: str): |
|
| 32 | """Put item into the queue.""" |
||
| 33 | |||
| 34 | return self._queue.enqueue(method, item, job=job) |
||
| 35 |