From e71b24af6dc3af1d1b6a7578b07b08e06f430d9f Mon Sep 17 00:00:00 2001 From: Elbek Khoshimjonov Date: Mon, 29 Jan 2024 13:49:49 -0500 Subject: [PATCH 1/2] RestartWorkflow panic policy --- internal/internal_task_handlers.go | 6 ++++++ internal/worker.go | 3 +++ worker/worker.go | 3 +++ 3 files changed, 12 insertions(+) diff --git a/internal/internal_task_handlers.go b/internal/internal_task_handlers.go index 2d78c8788..7f864d84a 100644 --- a/internal/internal_task_handlers.go +++ b/internal/internal_task_handlers.go @@ -1193,6 +1193,12 @@ func (w *workflowExecutionContextImpl) applyWorkflowPanicPolicy(workflowTask *wo w.getEventHandler().Complete(nil, NewApplicationError( "Workflow failed on panic due to FailWorkflow workflow panic policy", "", false, workflowError)) + case RestartWorkflow: + // return an error to restart the workflow + w.workflowInfo.continueAsNewSuggested = true + w.getEventHandler().Complete(nil, NewApplicationError( + "Restart", + "", false, workflowError)) case BlockWorkflow: // return error here will be convert to WorkflowTaskFailed for the first time, and ignored for subsequent // attempts which will cause WorkflowTaskTimeout and server will retry forever until issue got fixed or diff --git a/internal/worker.go b/internal/worker.go index df0b23fd2..675df9d4e 100644 --- a/internal/worker.go +++ b/internal/worker.go @@ -263,6 +263,9 @@ const ( // This feature is convenient during development. // WARNING: enabling this in production can cause all open workflows to fail on a single bug or bad deployment. FailWorkflow + // RestartWorkflow immediately restarts the workflow execution if workflow code throws panic or detects non-determinism. + // This feature is convenient if the workflows are finite state machines + RestartWorkflow ) // ReplayNamespace is namespace for replay because startEvent doesn't contain it diff --git a/worker/worker.go b/worker/worker.go index a66ce953e..a4de76b90 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -228,6 +228,9 @@ const ( // detects non-determinism. This feature is convenient during development. // WARNING: enabling this in production can cause all open workflows to fail on a single bug or bad deployment. FailWorkflow = internal.FailWorkflow + // RestartWorkflow immediately restarts the workflow execution if workflow code throws panic or detects non-determinism. + // This feature is convenient if the workflows are finite state machines + RestartWorkflow = internal.RestartWorkflow ) // New creates an instance of worker for managing workflow and activity executions. From e5a4c32375f38eba9344946e18d50293425d9a95 Mon Sep 17 00:00:00 2001 From: Elbek Khoshimjonov Date: Mon, 29 Jan 2024 14:48:08 -0500 Subject: [PATCH 2/2] semi-working version --- internal/internal_task_handlers.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/internal_task_handlers.go b/internal/internal_task_handlers.go index 7f864d84a..5df2df59b 100644 --- a/internal/internal_task_handlers.go +++ b/internal/internal_task_handlers.go @@ -1195,10 +1195,14 @@ func (w *workflowExecutionContextImpl) applyWorkflowPanicPolicy(workflowTask *wo "", false, workflowError)) case RestartWorkflow: // return an error to restart the workflow - w.workflowInfo.continueAsNewSuggested = true - w.getEventHandler().Complete(nil, NewApplicationError( - "Restart", - "", false, workflowError)) + // TODO: Get Workflow Context and inputs somehow and have a full ContinueAsNewError + // current error only works if the workflow does not have any input + w.getEventHandler().Complete(nil, &ContinueAsNewError{ + WorkflowType: &w.workflowInfo.WorkflowType, + TaskQueueName: w.workflowInfo.TaskQueueName, + WorkflowRunTimeout: w.workflowInfo.WorkflowRunTimeout, + WorkflowTaskTimeout: w.workflowInfo.WorkflowTaskTimeout, + }) case BlockWorkflow: // return error here will be convert to WorkflowTaskFailed for the first time, and ignored for subsequent // attempts which will cause WorkflowTaskTimeout and server will retry forever until issue got fixed or