Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions apps/workflow/src/app/api/workflow/cancel/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* API endpoint for cancelling paused workflows
* POST /api/workflow/cancel - Cancel a paused execution
*/

import { NextRequest, NextResponse } from "next/server";

export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { executionId, reason } = body;

if (!executionId) {
return NextResponse.json(
{ error: "executionId is required" },
{ status: 400 }
);
}

// In production, this would:
// 1. Remove from pausedExecutions in TriggerWorkflowManager
// 2. Mark execution as cancelled in ExecutionStore
// 3. Clean up any scheduled timeouts

// Example:
// triggerManager.cancelPausedExecution(executionId, reason);

console.log(`[API] Cancel workflow: ${executionId}`, reason);

// Mock success response
return NextResponse.json({
success: true,
executionId,
status: "cancelled",
message: "Workflow cancelled successfully",
});
} catch (error) {
console.error("[API] Failed to cancel workflow:", error);
return NextResponse.json(
{
error: "Failed to cancel workflow",
message: error instanceof Error ? error.message : String(error),
},
{ status: 500 }
);
}
}
53 changes: 53 additions & 0 deletions apps/workflow/src/app/api/workflow/resume/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* API endpoint for resuming paused workflows
* POST /api/workflow/resume - Resume a paused execution with data
*/

import { NextRequest, NextResponse } from "next/server";

export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { executionId, data } = body;

if (!executionId) {
return NextResponse.json(
{ error: "executionId is required" },
{ status: 400 }
);
}

// In production, this would:
// 1. Find the paused execution in TriggerWorkflowManager
// 2. Call resumeWorkflow() with the provided data
// 3. Return the result

// Example:
// const pausedExecution = triggerManager.findPausedExecution(executionId);
// const result = await resumeWorkflow(
// pausedExecution.workflow,
// registry,
// pausedExecution.pauseState,
// data
// );

console.log(`[API] Resume workflow: ${executionId}`, data);

// Mock success response
return NextResponse.json({
success: true,
executionId,
status: "resumed",
message: "Workflow resumed successfully",
});
} catch (error) {
console.error("[API] Failed to resume workflow:", error);
return NextResponse.json(
{
error: "Failed to resume workflow",
message: error instanceof Error ? error.message : String(error),
},
{ status: 500 }
);
}
}
Loading