MCPcopy Create free account
hub / github.com/diffgram/diffgram / process_new_event

Method process_new_event

eventhandlers/SchedulerConsumer.py:73–111  ·  view source on GitHub ↗

Receives a trigger event a fi queueclient = QueueClient()nds any actions matching the event trigger for action execution. :return:

(channel, method, properties, msg)

Source from the content-addressed store, hash-verified

71
72 @staticmethod
73 def process_new_event(channel, method, properties, msg):
74 """
75 Receives a trigger event a fi
76 queueclient = QueueClient()nds any actions
77 matching the event trigger for action
78 execution.
79 :return:
80 """
81 logger.debug(f'New Scheduler Message: {msg}')
82 msg_data = json.loads(msg)
83 log = regular_log.default()
84 if msg_data.get('workflow_id') is None:
85 log['error']['workflow_id'] = f'Message must contain workflow_id. Message is: {msg_data}'
86 if msg_data.get('project_id') is None:
87 log['error']['project_id'] = f'Message must contain project_id. Message is: {msg_data}'
88 if msg_data.get('action') is None:
89 log['error']['action'] = f'Message most contain an action. Message is: {msg_data}'
90 if msg_data.get('cron_expression') is None:
91 log['error']['cron_expression'] = f'Message must contain a cron_expression. Message is: {msg_data}'
92
93
94 if regular_log.log_has_error(log):
95 logger.error(f'Error processing jobs message: {log}')
96 return
97
98 workflow_id = msg_data.get('workflow_id')
99 project_id = msg_data.get('project_id')
100 action = msg_data.get('action')
101 cron_expression = msg_data.get('cron_expression')
102 logger.debug(f'Processing Scheduler event: {msg}')
103
104 with session_scope_threaded() as session:
105 if action == 'add':
106 diffgram_scheduler.add_job(job_id = workflow_id, cron_expr = cron_expression, func = trigger_workflow, args = [workflow_id, project_id])
107 elif action == 'remove':
108 diffgram_scheduler.remove_job(job_id = workflow_id)
109 else:
110 logger.warning(f'Scheduler Consumer: Unknown action type "{action}"')
111 logger.debug(f'Scheduler event processed successfully. {msg}')

Callers

nothing calls this directly

Calls 4

session_scope_threadedFunction · 0.90
add_jobMethod · 0.80
remove_jobMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected