diff --git a/internal/interceptor.go b/internal/interceptor.go index 569b52a28..9fb8238bb 100644 --- a/internal/interceptor.go +++ b/internal/interceptor.go @@ -200,10 +200,10 @@ type WorkflowOutboundInterceptor interface { // GetTypedSearchAttributes intercepts workflow.GetTypedSearchAttributes. GetTypedSearchAttributes(ctx Context) SearchAttributes - // GetUpdateInfo intercepts workflow.GetUpdateInfo. + // GetCurrentUpdateInfo intercepts workflow.GetCurrentUpdateInfo. // // NOTE: Experimental - GetUpdateInfo(ctx Context) *UpdateInfo + GetCurrentUpdateInfo(ctx Context) *UpdateInfo // GetLogger intercepts workflow.GetLogger. GetLogger(ctx Context) log.Logger diff --git a/internal/interceptor_base.go b/internal/interceptor_base.go index 239fd3963..455007bd8 100644 --- a/internal/interceptor_base.go +++ b/internal/interceptor_base.go @@ -233,9 +233,9 @@ func (w *WorkflowOutboundInterceptorBase) GetTypedSearchAttributes(ctx Context) return w.Next.GetTypedSearchAttributes(ctx) } -// GetUpdateInfo implements WorkflowOutboundInterceptor.GetUpdateInfo. -func (w *WorkflowOutboundInterceptorBase) GetUpdateInfo(ctx Context) *UpdateInfo { - return w.Next.GetUpdateInfo(ctx) +// GetCurrentUpdateInfo implements WorkflowOutboundInterceptor.GetCurrentUpdateInfo. +func (w *WorkflowOutboundInterceptorBase) GetCurrentUpdateInfo(ctx Context) *UpdateInfo { + return w.Next.GetCurrentUpdateInfo(ctx) } // GetLogger implements WorkflowOutboundInterceptor.GetLogger. diff --git a/internal/internal_update.go b/internal/internal_update.go index a86772e8d..52e4eb19e 100644 --- a/internal/internal_update.go +++ b/internal/internal_update.go @@ -275,7 +275,8 @@ func defaultUpdateHandler( updateRunner := func(ctx Context) { ctx = WithValue(ctx, updateInfoContextKey, &UpdateInfo{ - ID: id, + ID: id, + Name: name, }) eo := getWorkflowEnvOptions(ctx) diff --git a/internal/workflow.go b/internal/workflow.go index 7d29a62d1..e489c777e 100644 --- a/internal/workflow.go +++ b/internal/workflow.go @@ -1034,7 +1034,10 @@ type WorkflowInfo struct { // UpdateInfo information about a currently running update type UpdateInfo struct { + // ID of the update ID string + // Name of the update + Name string } // GetBinaryChecksum returns the binary checksum of the last worker to complete a task for this @@ -1094,12 +1097,12 @@ func (wc *workflowEnvironmentInterceptor) GetTypedSearchAttributes(ctx Context) } // GetUpdateInfo extracts info of a currently running update from a context. -func GetUpdateInfo(ctx Context) *UpdateInfo { +func GetCurrentUpdateInfo(ctx Context) *UpdateInfo { i := getWorkflowOutboundInterceptor(ctx) - return i.GetUpdateInfo(ctx) + return i.GetCurrentUpdateInfo(ctx) } -func (wc *workflowEnvironmentInterceptor) GetUpdateInfo(ctx Context) *UpdateInfo { +func (wc *workflowEnvironmentInterceptor) GetCurrentUpdateInfo(ctx Context) *UpdateInfo { uc := ctx.Value(updateInfoContextKey) if uc == nil { panic("getWorkflowOutboundInterceptor: No update associated with this context") diff --git a/test/workflow_test.go b/test/workflow_test.go index 2b6311ede..d554402df 100644 --- a/test/workflow_test.go +++ b/test/workflow_test.go @@ -354,10 +354,10 @@ func (w *Workflows) UpdateCancelableWorkflow(ctx workflow.Context) error { func (w *Workflows) UpdateInfoWorkflow(ctx workflow.Context) error { err := workflow.SetUpdateHandlerWithOptions(ctx, "update", func(ctx workflow.Context) (string, error) { - return workflow.GetUpdateInfo(ctx).ID, nil + return workflow.GetCurrentUpdateInfo(ctx).ID, nil }, workflow.UpdateHandlerOptions{ Validator: func(ctx workflow.Context) error { - if workflow.GetUpdateInfo(ctx).ID != "testID" { + if workflow.GetCurrentUpdateInfo(ctx).ID != "testID" { return errors.New("invalid update ID") } return nil diff --git a/workflow/workflow.go b/workflow/workflow.go index addd568ea..f8823a391 100644 --- a/workflow/workflow.go +++ b/workflow/workflow.go @@ -207,8 +207,12 @@ func GetTypedSearchAttributes(ctx Context) temporal.SearchAttributes { return internal.GetTypedSearchAttributes(ctx) } -func GetUpdateInfo(ctx Context) *UpdateInfo { - return internal.GetUpdateInfo(ctx) +// GetCurrentUpdateInfo returns information about the currently running update if any +// from the context. +// +// NOTE: Experimental +func GetCurrentUpdateInfo(ctx Context) *UpdateInfo { + return internal.GetCurrentUpdateInfo(ctx) } // GetLogger returns a logger to be used in workflow's context