|
@@ -45,7 +45,8 @@ from app.schemas.run import (
|
|
|
RunExecuteRequest,
|
|
RunExecuteRequest,
|
|
|
WorkflowRunStatusUpdateRequest,
|
|
WorkflowRunStatusUpdateRequest,
|
|
|
)
|
|
)
|
|
|
-from core_shared import JSONValue
|
|
|
|
|
|
|
+from core_shared import JSONValue, try_build_redis_client
|
|
|
|
|
+from core_shared.task_queue import TaskQueuePublisher
|
|
|
|
|
|
|
|
|
|
|
|
|
class RuntimeApplicationService:
|
|
class RuntimeApplicationService:
|
|
@@ -59,6 +60,7 @@ class RuntimeApplicationService:
|
|
|
execution_dispatcher: NodeExecutionDispatcher,
|
|
execution_dispatcher: NodeExecutionDispatcher,
|
|
|
workflow_client: WorkflowServiceClient | None = None,
|
|
workflow_client: WorkflowServiceClient | None = None,
|
|
|
event_client: EventServiceClient | None = None,
|
|
event_client: EventServiceClient | None = None,
|
|
|
|
|
+ task_queue_publisher: TaskQueuePublisher | None = None,
|
|
|
) -> None:
|
|
) -> None:
|
|
|
self.workflow_run_repository = workflow_run_repository
|
|
self.workflow_run_repository = workflow_run_repository
|
|
|
self.node_run_repository = node_run_repository
|
|
self.node_run_repository = node_run_repository
|
|
@@ -68,6 +70,7 @@ class RuntimeApplicationService:
|
|
|
self.execution_dispatcher = execution_dispatcher
|
|
self.execution_dispatcher = execution_dispatcher
|
|
|
self.workflow_client = workflow_client
|
|
self.workflow_client = workflow_client
|
|
|
self.event_client = event_client
|
|
self.event_client = event_client
|
|
|
|
|
+ self.task_queue_publisher = task_queue_publisher
|
|
|
|
|
|
|
|
def create_run(self, payload: RunCreateRequest) -> tuple[WorkflowRun, NodeRun | None]:
|
|
def create_run(self, payload: RunCreateRequest) -> tuple[WorkflowRun, NodeRun | None]:
|
|
|
initial_node = payload.initial_node or self._plan_initial_node(payload)
|
|
initial_node = payload.initial_node or self._plan_initial_node(payload)
|
|
@@ -118,6 +121,7 @@ class RuntimeApplicationService:
|
|
|
"status": initial_node.status,
|
|
"status": initial_node.status,
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
|
|
+ self._publish_node_run_to_queue(node_run)
|
|
|
|
|
|
|
|
self._log_event(
|
|
self._log_event(
|
|
|
tenant_id=payload.tenant_id,
|
|
tenant_id=payload.tenant_id,
|
|
@@ -402,6 +406,7 @@ class RuntimeApplicationService:
|
|
|
)
|
|
)
|
|
|
if retried_node_run is None:
|
|
if retried_node_run is None:
|
|
|
return None
|
|
return None
|
|
|
|
|
+ self._publish_node_run_to_queue(retried_node_run)
|
|
|
self.trace_span_repository.finish(
|
|
self.trace_span_repository.finish(
|
|
|
span_id=trace_span.id,
|
|
span_id=trace_span.id,
|
|
|
status="error",
|
|
status="error",
|
|
@@ -732,7 +737,7 @@ class RuntimeApplicationService:
|
|
|
):
|
|
):
|
|
|
continue
|
|
continue
|
|
|
scheduled_time, timeout_time = self._build_node_timing(successor_config)
|
|
scheduled_time, timeout_time = self._build_node_timing(successor_config)
|
|
|
- self.node_run_repository.create(
|
|
|
|
|
|
|
+ created = self.node_run_repository.create(
|
|
|
tenant_id=node_run.tenant_id,
|
|
tenant_id=node_run.tenant_id,
|
|
|
run_id=node_run.run_id,
|
|
run_id=node_run.run_id,
|
|
|
parent_node_run_id=node_run.id,
|
|
parent_node_run_id=node_run.id,
|
|
@@ -742,6 +747,7 @@ class RuntimeApplicationService:
|
|
|
scheduled_time=scheduled_time,
|
|
scheduled_time=scheduled_time,
|
|
|
timeout_time=timeout_time,
|
|
timeout_time=timeout_time,
|
|
|
)
|
|
)
|
|
|
|
|
+ self._publish_node_run_to_queue(created)
|
|
|
existing_node_counts[successor.node_id] = (
|
|
existing_node_counts[successor.node_id] = (
|
|
|
existing_node_counts.get(successor.node_id, 0) + 1
|
|
existing_node_counts.get(successor.node_id, 0) + 1
|
|
|
)
|
|
)
|
|
@@ -958,6 +964,7 @@ class RuntimeApplicationService:
|
|
|
scheduled_time=scheduled_time,
|
|
scheduled_time=scheduled_time,
|
|
|
timeout_time=timeout_time,
|
|
timeout_time=timeout_time,
|
|
|
)
|
|
)
|
|
|
|
|
+ self._publish_node_run_to_queue(created)
|
|
|
self._log_event(
|
|
self._log_event(
|
|
|
tenant_id=node_run.tenant_id,
|
|
tenant_id=node_run.tenant_id,
|
|
|
run_id=node_run.run_id,
|
|
run_id=node_run.run_id,
|
|
@@ -1143,12 +1150,21 @@ class RuntimeApplicationService:
|
|
|
except EventServiceClientError:
|
|
except EventServiceClientError:
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
|
|
+ def _publish_node_run_to_queue(self, node_run: NodeRun) -> None:
|
|
|
|
|
+ if node_run.status != "queued" or self.task_queue_publisher is None:
|
|
|
|
|
+ return
|
|
|
|
|
+ self.task_queue_publisher.publish_runtime_node_run(
|
|
|
|
|
+ tenant_id=node_run.tenant_id,
|
|
|
|
|
+ node_run_id=node_run.id,
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
|
|
|
def build_runtime_application_service(
|
|
def build_runtime_application_service(
|
|
|
*,
|
|
*,
|
|
|
db: Session,
|
|
db: Session,
|
|
|
settings: RuntimeServiceSettings,
|
|
settings: RuntimeServiceSettings,
|
|
|
) -> RuntimeApplicationService:
|
|
) -> RuntimeApplicationService:
|
|
|
|
|
+ redis_client = try_build_redis_client(settings.redis_url)
|
|
|
return RuntimeApplicationService(
|
|
return RuntimeApplicationService(
|
|
|
workflow_run_repository=WorkflowRunRepository(db),
|
|
workflow_run_repository=WorkflowRunRepository(db),
|
|
|
node_run_repository=NodeRunRepository(db),
|
|
node_run_repository=NodeRunRepository(db),
|
|
@@ -1173,4 +1189,7 @@ def build_runtime_application_service(
|
|
|
base_url=settings.event_service_url,
|
|
base_url=settings.event_service_url,
|
|
|
timeout_seconds=settings.event_service_timeout_seconds,
|
|
timeout_seconds=settings.event_service_timeout_seconds,
|
|
|
),
|
|
),
|
|
|
|
|
+ task_queue_publisher=(
|
|
|
|
|
+ TaskQueuePublisher(client=redis_client) if redis_client is not None else None
|
|
|
|
|
+ ),
|
|
|
)
|
|
)
|