fix: update search attribute keys and improve schedule handling

- Changed search attribute key from "Orchestrated" to "orchestrated" in temporal_manager.py and test cases.
- Enhanced logging for schedule creation and updates in temporal_manager.py.
- Updated schedule creation to use workflow_type directly instead of a hardcoded string.
- Modified gather_read_tags function to use server_id instead of server_name for tag identification.
- Adjusted test cases to reflect changes in server_id usage and ensure consistency across tests.
- Fixed model_name retrieval in common_config to access nested models dictionary.
- Updated test cases to align with new data structures and ensure accurate assertions.
This commit is contained in:
vitor-aignosi
2025-06-04 15:06:54 -03:00
parent 5dc49b476a
commit dcbcc70651
9 changed files with 176 additions and 139 deletions

View File

@@ -46,6 +46,11 @@ class Formatters(BaseActivity):
schedule_config[pipeline['schedule_name']
] = predictions_batch(pipeline)
self.logger.info("Processed schedules")
self.logger.debug(json.dumps(
schedule_config, indent=4, sort_keys=True))
return schedule_config
@activity.defn(name="process_slots")
@@ -74,7 +79,7 @@ class Formatters(BaseActivity):
opc_servers = {}
for server in opc_servers_list:
opc_servers[server['server_name']] = {
opc_servers[server['id']] = {
**server,
}
@@ -99,6 +104,10 @@ class Formatters(BaseActivity):
slot_config = build_tag_config(
tag, slot_config.copy(), opc_servers, number_of_slots)
self.logger.info("Processed slots")
self.logger.debug(json.dumps(
slot_config, indent=4, sort_keys=True))
return slot_config
@activity.defn(name="create_schedule_config")
@@ -131,7 +140,16 @@ class Formatters(BaseActivity):
for schedule_name, schedule in schedule_config.items():
if schedule_name in current_schedule_config:
if schedule != current_schedule_config[schedule_name]['data']:
self.logger.debug(f"{current_schedule_config[schedule_name]}")
old_config = current_schedule_config[schedule_name]['data']
self.logger.debug(f"Comparing {schedule_name}:")
self.logger.debug(json.dumps(
old_config, indent=4, sort_keys=True))
self.logger.debug(json.dumps(
schedule, indent=4, sort_keys=True))
if schedule != old_config:
to_update[schedule_name] = schedule
elif schedule_name not in current_schedule_config:
@@ -141,12 +159,18 @@ class Formatters(BaseActivity):
if schedule_name not in schedule_config:
to_delete.append(schedule_name)
return {
output = {
"to_update": to_update,
"to_create": to_create,
"to_delete": to_delete
}
self.logger.info("Created schedule config")
self.logger.debug(json.dumps(
output, indent=4, sort_keys=True))
return output
@activity.defn(name="create_slot_config")
async def create_slot_config(self,
input_data: dict[str, Any]) -> dict[str, Any]:
@@ -179,11 +203,17 @@ class Formatters(BaseActivity):
to_delete = [str(i) for i in range(
number_of_slots + 1, number_of_current_slots + 1)]
return {
output = {
"to_delete": to_delete,
"to_insert": slot_config
}
self.logger.info("Created slot config")
self.logger.debug(json.dumps(
output, indent=4, sort_keys=True))
return output
def send_success_report(self, message: str, notification_id: str) -> None:
self.notification_handler.build_and_send_notification(
notification_id,

View File

@@ -49,7 +49,7 @@ class TemporalManager(BaseActivity):
async for schedule in await self.temporal_client.list_schedules():
search_attrs = getattr(schedule, "search_attributes", {})
if search_attrs.get("Orchestrated", ["false"]) == ["true"]:
if search_attrs.get("orchestrated", ["false"]) == ["true"]:
schedule_id = schedule.id
handle = self.temporal_client.get_schedule_handle(schedule_id)
@@ -113,14 +113,18 @@ class TemporalManager(BaseActivity):
workflow_type = schedule['workflow_type']
try:
self.logger.debug(f"Creating schedule {schedule_name}:")
self.logger.debug(json.dumps(
schedule, indent=4, sort_keys=True))
await self.temporal_client.create_schedule(
schedule_name,
Schedule(
action=ScheduleActionStartWorkflow(
workflow=workflow_type,
args=schedule,
workflow_type,
schedule,
id=schedule_name,
task_queue=f"{workflow_type}-queue"
task_queue=f"{workflow_type}-queue",
execution_timeout=timedelta(minutes=2)
),
spec=ScheduleSpec(
intervals=[
@@ -181,8 +185,14 @@ class TemporalManager(BaseActivity):
async def update_schedule(input_data: ScheduleUpdateInput) -> ScheduleUpdate:
schedule_action = input_data.description.schedule.action
self.logger.debug("Updating schedule:")
if hasattr(schedule_action, "args"):
schedule_action.args = schedule
self.logger.debug("New schedule:")
self.logger.debug(json.dumps(
schedule, indent=4, sort_keys=True))
schedule_action.args = [schedule]
input_data.description.schedule.spec.intervals = [
ScheduleIntervalSpec(