def find_and_modify_topic_data(topic_name, query, update_data): collection_name = build_collection_name(topic_name) codec_options = build_code_options() collection = db.get_collection(collection_name, codec_options=codec_options) old_value = collection.find_one_and_update(filter=query, update=update_data, upsert=True) trigger_pipeline(topic_name, {pipeline_constants.NEW: update_data, pipeline_constants.OLD: old_value}, TriggerType.update)
def insert_topic_data(topic_name, mapping_result, pipeline_uid): collection_name = build_collection_name(topic_name) codec_options = build_code_options() collection = db.get_collection(collection_name, codec_options=codec_options) add_audit_columns(mapping_result, INSERT) add_trace_columns(mapping_result, "insert_row", pipeline_uid) collection.insert(mapping_result) trigger_pipeline(topic_name, {pipeline_constants.NEW: mapping_result, pipeline_constants.OLD: None}, TriggerType.insert)
def find_and_modify_topic_data(topic_name, query, update_data, target_data): collection_name = build_collection_name(topic_name) collection = db.get_collection(collection_name) old_data = find_topic_data_by_id(collection, target_data["_id"]) collection.find_and_modify(query=query, update=update_data) trigger_pipeline(topic_name, { pipeline_constants.NEW: update_data, pipeline_constants.OLD: old_data }, TriggerType.update)
def update_topic_data(topic_name, mapping_result, target_data, pipeline_uid): collection_name = build_collection_name(topic_name) codec_options = build_code_options() collection = db.get_collection(collection_name, codec_options=codec_options) old_data = find_topic_data_by_id(collection, target_data["_id"]) add_audit_columns(mapping_result, UPDATE) add_trace_columns(mapping_result, "update_row", pipeline_uid) collection.update_one({"_id": target_data["_id"]}, {"$set": mapping_result}) data = {**target_data, **mapping_result} trigger_pipeline(topic_name, {pipeline_constants.NEW: data, pipeline_constants.OLD: old_data}, TriggerType.update)
def sync_alarm_message(alarm: AlarmMessage): topic_event = TopicEvent(code="alarm", data=alarm.dict()) topic = get_topic(topic_event.code) if topic is None: raise Exception("topic name does not exist") add_audit_columns(topic_event.data, INSERT) save_topic_instance(topic_event.code, topic_event.data) trigger_pipeline(topic_event.code, { pipeline_constants.NEW: topic_event.data, pipeline_constants.OLD: None }, TriggerType.insert) asyncio.ensure_future(send_notifier(alarm))
async def __trigger_pipeline(topic_event): trigger_pipeline(topic_event.code, { pipeline_constants.NEW: topic_event.data, pipeline_constants.OLD: None }, TriggerType.insert)
async def run_pipeline(topic_event, current_user, trace_id=None): trigger_pipeline(topic_event.code, {pipeline_constants.NEW: topic_event.data, pipeline_constants.OLD: None}, TriggerType.insert, current_user, trace_id)