Skip to content

Add new endpoint to manually trigger workflows#1089

Merged
bigfluffycookie merged 23 commits intomainfrom
lb/ops-2273
Aug 8, 2025
Merged

Add new endpoint to manually trigger workflows#1089
bigfluffycookie merged 23 commits intomainfrom
lb/ops-2273

Conversation

@bigfluffycookie
Copy link
Copy Markdown
Contributor

Fixes OPS-2273

@linear
Copy link
Copy Markdown

linear bot commented Aug 5, 2025

return project.ownerId;
}

async function validateTriggerType(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone knows an easier way to verify that the trigger is of strategy polling, lmk

@bigfluffycookie bigfluffycookie marked this pull request as ready for review August 6, 2025 08:51
@bigfluffycookie bigfluffycookie requested review from MarceloRGonc, Copilot and rSnapkoOpenOps and removed request for Copilot August 6, 2025 08:51
Copilot AI review requested due to automatic review settings August 6, 2025 12:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new endpoint /v1/flows/{id}/run to manually trigger workflow executions. The implementation restricts manual triggering to only polling-type workflows and requires the workflow to be published.

Key Changes:

  • Add POST endpoint for manual workflow execution with validation
  • Implement trigger type validation to ensure only polling workflows can be manually triggered
  • Add comprehensive test coverage for the new endpoint including error cases

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/server/api/src/app/flows/flow/flow.controller.ts Implements the new /run endpoint with validation logic and error handling
packages/server/api/test/integration/ce/flows/flow.test.ts Adds integration tests covering unpublished flows, non-polling triggers, and successful execution scenarios

): Promise<{ success: boolean; message: string }> {
const blockTrigger = flow.version.trigger;

if (blockTrigger.type !== TriggerType.BLOCK) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never happen. If the workflow is published, you must have a trigger. And there are only block triggers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theres TriggerType.Empty in the enum, which is why im doing it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to do this. But if this happens, we have a bug. TriggerType.Empty only exists when you create the workflow and have no trigger selected. And without selecting a trigger, you can't publish.

Comment on lines +200 to +209
if (
error instanceof ApplicationError &&
error.error?.code === ErrorCode.ENTITY_NOT_FOUND
) {
return reply.status(StatusCodes.BAD_REQUEST).send({
success: false,
message:
'Workflow must be published before it can be triggered manually',
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we check if the workflow is published. Is it possible to reach this catch for that reason?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed the message

});

return {
success: metadata.type === TriggerStrategy.POLLING,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need WEBHOOK triggers here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? with the webhook i thought you can just go through the normal webhook logic, once you built it cant you just invoke it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. But won't it affect running workflows by AI agent in future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rita says no need for a new endpoint for webhooks, I guess we will get to it when it comes up then, but i think agents are able to invoke urls also

@bigfluffycookie bigfluffycookie changed the base branch from main to lb/ops-2276 August 6, 2025 15:52
Base automatically changed from lb/ops-2276 to main August 8, 2025 07:48
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Aug 8, 2025

@bigfluffycookie bigfluffycookie merged commit d19a613 into main Aug 8, 2025
18 of 19 checks passed
@bigfluffycookie bigfluffycookie deleted the lb/ops-2273 branch August 8, 2025 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants