Skip to content

Commit

Permalink
Change GetUpdateInfo to GetCurrentUpdateInfo (#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinn-With-Two-Ns authored Jun 6, 2024
1 parent bf29944 commit 9ecb2a4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions internal/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions internal/interceptor_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion internal/internal_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ func defaultUpdateHandler(

updateRunner := func(ctx Context) {
ctx = WithValue(ctx, updateInfoContextKey, &UpdateInfo{
ID: id,
ID: id,
Name: name,
})

eo := getWorkflowEnvOptions(ctx)
Expand Down
9 changes: 6 additions & 3 deletions internal/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions test/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions workflow/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9ecb2a4

Please sign in to comment.