#!/usr/bin/env python3 # -*-coding:UTF-8 -* """ The SYNC Module ================================ This module . """ ################################## # Import External packages ################################## import os import sys import time sys.path.append(os.environ['AIL_BIN']) ################################## # Import Project packages ################################## from core import ail_2_ail from lib.objects.Items import Item from modules.abstract_module import AbstractModule class Sync_module(AbstractModule): """ Sync_module module for AIL framework """ def __init__(self): super(Sync_module, self).__init__() # Waiting time in seconds between to message processed self.pending_seconds = 10 self.dict_sync_queues = ail_2_ail.get_all_sync_queue_dict() self.last_refresh = time.time() print(self.dict_sync_queues) # Send module state to logs self.logger.info(f'Module {self.module_name} Launched') def compute(self, message): ### REFRESH DICT if self.last_refresh < ail_2_ail.get_last_updated_sync_config(): self.last_refresh = time.time() self.dict_sync_queues = ail_2_ail.get_all_sync_queue_dict() print('sync queues refreshed') print(self.dict_sync_queues) obj = self.get_obj() tags = obj.get_tags() # check filter + tags # print(message) for queue_uuid in self.dict_sync_queues: filter_tags = self.dict_sync_queues[queue_uuid]['filter'] if filter_tags and tags: # print('tags: {tags} filter: {filter_tags}') if filter_tags.issubset(tags): obj_dict = obj.get_default_meta() # send to queue push and/or pull for dict_ail in self.dict_sync_queues[queue_uuid]['ail_instances']: print(f'ail_uuid: {dict_ail["ail_uuid"]} obj: {message}') ail_2_ail.add_object_to_sync_queue(queue_uuid, dict_ail['ail_uuid'], obj_dict, push=dict_ail['push'], pull=dict_ail['pull']) if __name__ == '__main__': module = Sync_module() module.run()