chore(): improve workflow engine storage (#13345)

* chore(workflow-engines): Improve race condition management

* cleanup

* cleanup

* chore(workflow-engines): Improve race condition management

* chore(workflow-engines): Improve race condition management

* chore(workflow-engines): heartbeat extend TTL

* Refactor chore title for workflow engine improvements

* chore(): Improve workflow execution db interaction

* chore(): Improve workflow execution db interaction

* chore(): Improve workflow execution db interaction

* chore(): Improve workflow execution db interaction

* chore(): Improve workflow execution db interaction

* chore(): Improve workflow execution db interaction

* chore(): Improve workflow execution db interaction

* chore(): Improve workflow execution db interaction

* chore(): Improve workflow execution db interaction

* update tests

* revert idempotent

* add run_id index + await deletion

* improve saving

* comment

* remove only

---------

Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2025-09-02 11:18:12 +02:00
committed by GitHub
parent b85a46e85b
commit bd206cb250
10 changed files with 255 additions and 48 deletions

View File

@@ -144,7 +144,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
describe("Cancel transaction", function () {
it("should cancel an ongoing execution with async unfinished yet step", (done) => {
const transactionId = "transaction-to-cancel-id"
const transactionId = "transaction-to-cancel-id" + ulid()
const step1 = createStep("step1", async () => {
return new StepResponse("step1")
})
@@ -205,7 +205,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
it("should cancel a complete execution with a sync workflow running as async", async () => {
const workflowId = "workflow-to-cancel-id" + ulid()
const transactionId = "transaction-to-cancel-id"
const transactionId = "transaction-to-cancel-id" + ulid()
const step1 = createStep("step1", async () => {
return new StepResponse("step1")
})
@@ -257,7 +257,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
it("should cancel an ongoing execution with a sync workflow running as async", async () => {
const workflowId = "workflow-to-cancel-id" + ulid()
const transactionId = "transaction-to-cancel-id"
const transactionId = "transaction-to-cancel-id" + ulid()
const step1 = createStep("step1", async () => {
return new StepResponse("step1")
})
@@ -309,7 +309,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
})
it("should cancel an ongoing execution with sync steps only", async () => {
const transactionId = "transaction-to-cancel-id"
const transactionId = "transaction-to-cancel-id" + ulid()
const step1 = createStep("step1", async () => {
return new StepResponse("step1")
})
@@ -356,7 +356,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
})
it("should prevent executing twice the same workflow in perfect concurrency with the same transactionId and non idempotent and not async but retention time is set", async () => {
const transactionId = "transaction_id"
const transactionId = "transaction_id" + ulid()
const workflowId = "workflow_id" + ulid()
const step1 = createStep("step1", async () => {
@@ -397,10 +397,11 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
it("should execute an async workflow keeping track of the event group id provided in the context", async () => {
const eventGroupId = "event-group-id"
const transactionId = "transaction_id" + ulid()
await workflowOrcModule.run(eventGroupWorkflowId, {
input: {},
transactionId: "transaction_id",
transactionId,
context: {
eventGroupId,
},
@@ -412,7 +413,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
action: TransactionHandlerType.INVOKE,
stepId: "step_1_event_group_id_background",
workflowId: eventGroupWorkflowId,
transactionId: "transaction_id",
transactionId,
},
stepResponse: { hey: "oh" },
})
@@ -427,9 +428,10 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
})
it("should execute an async workflow keeping track of the event group id that has been auto generated", async () => {
const transactionId = "transaction_id_2" + ulid()
await workflowOrcModule.run(eventGroupWorkflowId, {
input: {},
transactionId: "transaction_id_2",
transactionId,
throwOnError: true,
})
@@ -438,7 +440,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
action: TransactionHandlerType.INVOKE,
stepId: "step_1_event_group_id_background",
workflowId: eventGroupWorkflowId,
transactionId: "transaction_id_2",
transactionId,
},
stepResponse: { hey: "oh" },
})
@@ -582,12 +584,13 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
})
it("should return a list of workflow executions and keep it saved when there is a retentionTime set", async () => {
const transactionId = "transaction_1" + ulid()
await workflowOrcModule.run("workflow_2", {
input: {
value: "123",
},
throwOnError: true,
transactionId: "transaction_1",
transactionId,
})
let { data: executionsList } = await query.graph({
@@ -602,7 +605,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
action: TransactionHandlerType.INVOKE,
stepId: "new_step_name",
workflowId: "workflow_2",
transactionId: "transaction_1",
transactionId,
},
stepResponse: { uhuuuu: "yeaah!" },
})
@@ -624,7 +627,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
})
it("should return a list of workflow executions and keep it saved when there is a retentionTime set but allow for executing the same workflow multiple times with different run_id if the workflow is considered done", async () => {
const transactionId = "transaction_1"
const transactionId = "transaction_1" + ulid()
await workflowOrcModule.run(
"workflow_not_idempotent_with_retention",
{
@@ -716,7 +719,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
})
it("should subscribe to a async workflow and receive the response when it finishes", (done) => {
const transactionId = "trx_123"
const transactionId = "trx_123" + ulid()
const onFinish = jest.fn(() => {
done()
@@ -766,7 +769,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
it("should cancel and revert a non idempotent completed workflow with rentention time given a specific transaction id", async () => {
const workflowId = "workflow_not_idempotent_with_retention"
const transactionId = "trx_123"
const transactionId = "trx_123" + ulid()
await workflowOrcModule.run(workflowId, {
input: {
@@ -919,6 +922,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
})
it("should fetch an idempotent workflow after its completion", async () => {
const transactionId = "transaction_1" + ulid()
const { transaction: firstRun } = (await workflowOrcModule.run(
"workflow_idempotent",
{
@@ -926,7 +930,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
value: "123",
},
throwOnError: true,
transactionId: "transaction_1",
transactionId,
}
)) as Awaited<{ transaction: DistributedTransactionType }>
@@ -942,7 +946,7 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
value: "123",
},
throwOnError: true,
transactionId: "transaction_1",
transactionId,
}
)) as Awaited<{ transaction: DistributedTransactionType }>