From 6f2668eff1a115d512d2bc0c86fa6fb7b670ec30 Mon Sep 17 00:00:00 2001 From: terrtia Date: Wed, 13 Mar 2024 14:04:23 +0100 Subject: [PATCH] chg: [tools] reprocess objects by type --- bin/lib/ail_core.py | 3 +++ bin/lib/ail_queues.py | 4 ++++ tools/reprocess_objects.py | 46 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100755 tools/reprocess_objects.py diff --git a/bin/lib/ail_core.py b/bin/lib/ail_core.py index 44cd1359..9530b75d 100755 --- a/bin/lib/ail_core.py +++ b/bin/lib/ail_core.py @@ -54,6 +54,9 @@ def generate_uuid(): def get_all_objects(): return AIL_OBJECTS +def is_object_type(obj_type): + return obj_type in AIL_OBJECTS + def get_objects_with_subtypes(): return AIL_OBJECTS_WITH_SUBTYPES diff --git a/bin/lib/ail_queues.py b/bin/lib/ail_queues.py index 451fcc47..e91f42b9 100755 --- a/bin/lib/ail_queues.py +++ b/bin/lib/ail_queues.py @@ -139,6 +139,10 @@ class AILQueue: def error(self): r_queues.hdel(f'modules', f'{self.pid}:{self.name}') + def end(self): + self.clear() + r_queues.hdel(f'modules', f'{self.pid}:{self.name}') + def get_queues_modules(): return r_queues.hkeys('queues') diff --git a/tools/reprocess_objects.py b/tools/reprocess_objects.py new file mode 100755 index 00000000..6d0ffd16 --- /dev/null +++ b/tools/reprocess_objects.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Reprocess AIL Objects by Object Type +================ + +Send ALL objects by type in queues + +""" + +import argparse +import os +import sys + +sys.path.append(os.environ['AIL_BIN']) +################################## +# Import Project packages +################################## +from lib.ail_core import is_object_type +from lib import ail_queues +from lib.objects import ail_objects + +def reprocess_message_objects(object_type): + queue = ail_queues.AILQueue('FeederModuleImporter', -1) + for obj in ail_objects.obj_iterator(object_type, filters={}): + queue.send_message(obj.get_global_id(), message='reprocess') + queue.end() + + +if __name__ == "__main__": + + parser = argparse.ArgumentParser(description='Reprocess AIL Objects') + parser.add_argument('-t', '--type', type=str, help='AIL Object Type', required=True) + + args = parser.parse_args() + if not args.type: + parser.print_help() + sys.exit(0) + + obj_type = args.type + if not is_object_type(obj_type): + raise Exception(f'Invalid Object Type: {obj_type}') + if obj_type not in ['item', 'message']: # TODO image + raise Exception(f'Currently not supported Object Type: {obj_type}') + + reprocess_message_objects(obj_type) \ No newline at end of file