|
|
@@ -25,28 +25,28 @@ class WorkflowEngine:
|
|
|
self, task_id: str, workflow: Workflow, inputs: dict[str, Any]
|
|
|
) -> WorkflowResult:
|
|
|
total_steps = len(workflow.order)
|
|
|
- logger.info("[%s] ========== Workflow start ========== version=%s, total_steps=%d",
|
|
|
- task_id, workflow.version, total_steps)
|
|
|
+ logger.info("========== Workflow start ========== version=%s, total_steps=%d",
|
|
|
+ workflow.version, total_steps)
|
|
|
wf_t0 = time.time()
|
|
|
|
|
|
ctx = ExecutionContext(inputs)
|
|
|
|
|
|
try:
|
|
|
workspace = create_task_workspace(task_id, workflow.template_path)
|
|
|
- logger.info("[%s] Workspace created: %s", task_id, workspace)
|
|
|
+ logger.info("Workspace created: %s", workspace)
|
|
|
except Exception as e:
|
|
|
- logger.error("[%s] Failed to create workspace: %s", task_id, e)
|
|
|
+ logger.error("Failed to create workspace: %s", e)
|
|
|
return WorkflowResult.failure(f"failed: {e}")
|
|
|
|
|
|
for idx, step_id in enumerate(workflow.order, 1):
|
|
|
step = workflow.steps.get(step_id)
|
|
|
if step is None:
|
|
|
- logger.warning("[%s] Step '%s' not found in steps definition, skipping", task_id, step_id)
|
|
|
+ logger.warning("Step '%s' not found in steps definition, skipping", step_id)
|
|
|
continue
|
|
|
|
|
|
- logger.info("[%s] ------ Step %d/%d [%s] type=%s start ------",
|
|
|
- task_id, idx, total_steps, step.id, step.type)
|
|
|
- logger.info("[%s] [%s] raw_inputs=%s", task_id, step.id, step.inputs)
|
|
|
+ logger.info("------ Step %d/%d [%s] type=%s start ------",
|
|
|
+ idx, total_steps, step.id, step.type)
|
|
|
+ logger.info("[%s] raw_inputs=%s", step.id, step.inputs)
|
|
|
|
|
|
step_t0 = time.time()
|
|
|
try:
|
|
|
@@ -56,31 +56,31 @@ class WorkflowEngine:
|
|
|
step_elapsed = time.time() - step_t0
|
|
|
|
|
|
if result.is_failure():
|
|
|
- logger.error("[%s] [%s] FAILED in %.2fs after retries. Error: %s",
|
|
|
- task_id, step_id, step_elapsed, result.error_message)
|
|
|
+ logger.error("[%s] FAILED in %.2fs after retries. Error: %s",
|
|
|
+ step_id, step_elapsed, result.error_message)
|
|
|
return WorkflowResult.failure(
|
|
|
f"Step {step_id} failed: {result.error_message}"
|
|
|
)
|
|
|
except Exception as e:
|
|
|
step_elapsed = time.time() - step_t0
|
|
|
- logger.error("[%s] [%s] EXCEPTION in %.2fs: %s", task_id, step_id, step_elapsed, e, exc_info=True)
|
|
|
+ logger.error("[%s] EXCEPTION in %.2fs: %s", step_id, step_elapsed, e, exc_info=True)
|
|
|
return WorkflowResult.failure(f"Step {step_id} failed: {e}")
|
|
|
|
|
|
- logger.info("[%s] [%s] SUCCESS in %.2fs outputs=%s",
|
|
|
- task_id, step.id, step_elapsed, _shorten(result.outputs))
|
|
|
+ logger.info("[%s] SUCCESS in %.2fs outputs=%s",
|
|
|
+ step.id, step_elapsed, _shorten(result.outputs))
|
|
|
ctx.put_step_result(step_id, result.outputs)
|
|
|
|
|
|
- logger.info("[%s] All steps completed, resolving final outputs ...", task_id)
|
|
|
+ logger.info("All steps completed, resolving final outputs ...")
|
|
|
outputs: dict[str, Any] = {}
|
|
|
if workflow.outputs:
|
|
|
for key, value in workflow.outputs.items():
|
|
|
outputs[key] = self._resolver.resolve(value, ctx)
|
|
|
- logger.info("[%s] Final output_keys=%s", task_id, list(outputs.keys()))
|
|
|
+ logger.info("Final output_keys=%s", list(outputs.keys()))
|
|
|
|
|
|
cleanup_workspace(workspace, task_id)
|
|
|
total_elapsed = time.time() - wf_t0
|
|
|
- logger.info("[%s] ========== Workflow end ========== total_elapsed=%.2fs, success=True",
|
|
|
- task_id, total_elapsed)
|
|
|
+ logger.info("========== Workflow end ========== total_elapsed=%.2fs, success=True",
|
|
|
+ total_elapsed)
|
|
|
return WorkflowResult.ok(outputs)
|
|
|
|
|
|
def _execute_step_with_retry(
|
|
|
@@ -101,32 +101,32 @@ class WorkflowEngine:
|
|
|
)
|
|
|
|
|
|
if attempt > 0:
|
|
|
- logger.info("[%s] [%s] Retry attempt %d/%d",
|
|
|
- task_id, step.id, attempt, max_retries)
|
|
|
+ logger.info("[%s] Retry attempt %d/%d",
|
|
|
+ step.id, attempt, max_retries)
|
|
|
|
|
|
- logger.info("[%s] [%s] Executing task type=%s, resolved_input_keys=%s",
|
|
|
- task_id, step.id, step.type, list(step_inputs.keys()))
|
|
|
+ logger.info("[%s] Executing task type=%s, resolved_input_keys=%s",
|
|
|
+ step.id, step.type, list(step_inputs.keys()))
|
|
|
|
|
|
attempt_t0 = time.time()
|
|
|
last_result = task.execute(param)
|
|
|
attempt_elapsed = time.time() - attempt_t0
|
|
|
|
|
|
if last_result.is_success():
|
|
|
- logger.info("[%s] [%s] Task returned SUCCESS in %.2fs",
|
|
|
- task_id, step.id, attempt_elapsed)
|
|
|
+ logger.info("[%s] Task returned SUCCESS in %.2fs",
|
|
|
+ step.id, attempt_elapsed)
|
|
|
return last_result
|
|
|
|
|
|
if attempt < max_retries:
|
|
|
logger.warning(
|
|
|
- "[%s] [%s] Task returned FAILURE in %.2fs (attempt %d/%d), will retry. Error: %s",
|
|
|
- task_id, step.id, attempt_elapsed,
|
|
|
+ "[%s] Task returned FAILURE in %.2fs (attempt %d/%d), will retry. Error: %s",
|
|
|
+ step.id, attempt_elapsed,
|
|
|
attempt + 1, max_retries + 1, last_result.error_message,
|
|
|
)
|
|
|
time.sleep(1)
|
|
|
else:
|
|
|
logger.error(
|
|
|
- "[%s] [%s] Task returned FAILURE in %.2fs (final attempt %d/%d). Error: %s",
|
|
|
- task_id, step.id, attempt_elapsed,
|
|
|
+ "[%s] Task returned FAILURE in %.2fs (final attempt %d/%d). Error: %s",
|
|
|
+ step.id, attempt_elapsed,
|
|
|
attempt + 1, max_retries + 1, last_result.error_message,
|
|
|
)
|
|
|
|