Skip to content

Commit

Permalink
remove UpdateHandler
Browse files Browse the repository at this point in the history
The new version of the temporal SDK changes the signature of the
UpdateWorkflow method. To keep compatibility with old and new versions
of the SDK, I'm removing the method from this library. If anyone wants
it back, I can add it with the new SDK version in a future release.
  • Loading branch information
vikstrous committed Jun 25, 2024
1 parent c5dbd03 commit 9fcbe3c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 53 deletions.
13 changes: 0 additions & 13 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var queueMain = tempts.NewQueue(tempts.DefaultNamespace, "main")
var (
workflowTypeFormatAndGreet = tempts.NewWorkflow[string, string](queueMain, "format_and_greet")
workflowTypeFormatAndGreetGetName = tempts.NewQueryHandler[struct{}, string]("get_formatted_name")
workflowTypeFormatAndGreetSetName = tempts.NewUpdateHandler[string, string]("set_formatted_name")
activityTypeFormatName = tempts.NewActivity[string, string](queueMain, "format_name")
)

Expand Down Expand Up @@ -59,14 +58,6 @@ func main() {
panic(err)
}
fmt.Printf("Expecting unknown name from the query: %s\n", newName)
// TODO: uncomment this after testing with the feature enabled in temporal
//
// time.Sleep(time.Second) // wait for the name to be formatted, then replace it
// newName, err = workflowTypeFormatAndGreetSetName.Update(ctx, c, workflowHandle.GetID(), workflowHandle.GetRunID(), "Roger")
// if err != nil {
// panic(err)
// }
// fmt.Printf("Name returned from the update: %s\n", newName)

err = workflowHandle.Get(ctx, &newName)
if err != nil {
Expand Down Expand Up @@ -98,10 +89,6 @@ func workflowFormatAndGreet(ctx workflow.Context, name string) (string, error) {
workflowTypeFormatAndGreetGetName.SetHandler(ctx, func(struct{}) (string, error) {
return newName, nil
})
workflowTypeFormatAndGreetSetName.SetHandler(ctx, func(ctx workflow.Context, p string) (string, error) {
newName = p
return p, nil
})

// Give the example code a chance to read the "unknown" name with the query and update it
workflow.Sleep(ctx, time.Second*1)
Expand Down
40 changes: 0 additions & 40 deletions query_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,43 +36,3 @@ func (q *QueryHandler[Param, Return]) Query(ctx context.Context, temporalClient
}
return value, nil
}

// UpdateHandler is used for interacting with updates on workflows.
// Currently there's no way to enforce the connection between the update and the workflow it should be valid on.
type UpdateHandler[Param, Return any] struct {
name string
}

// NewUpdateHandler declares the name and types for an update to a workflow.
func NewUpdateHandler[Param, Return any](updateName string) *UpdateHandler[Param, Return] {
return &UpdateHandler[Param, Return]{name: updateName}
}

// SetHandler should be called by a workflow to define how the update should be handled when sent to this workflow to execute.
func (q *UpdateHandler[Param, Return]) SetHandler(ctx workflow.Context, fn func(workflow.Context, Param) (Return, error)) {
// This can't error because the type is enforced by the signature of this function
workflow.SetUpdateHandler(ctx, q.name, fn)
}

// SetHandlerWithValidator should be called by a workflow to define how the query should be handled when sent to this workflow to execute.
// This is the same as SetHandler, except that it gives access to the experimental Validator function which can be used to validate the request before it's executed.
func (q *UpdateHandler[Param, Return]) SetHandlerWithValidator(ctx workflow.Context, fn func(workflow.Context, Param) (Return, error), validator func(workflow.Context, Param) error) {
// This can't error because the type is enforced by the signature of this function
workflow.SetUpdateHandlerWithOptions(ctx, q.name, fn, workflow.UpdateHandlerOptions{
Validator: validator,
})
}

// Update executes the update and returns the response.
func (q *UpdateHandler[Param, Return]) Update(ctx context.Context, temporalClient *Client, workflowID, runID string, p Param) (Return, error) {
var value Return
response, err := temporalClient.Client.UpdateWorkflow(ctx, workflowID, runID, q.name, p)
if err != nil {
return value, err
}
err = response.Get(ctx, &value)
if err != nil {
return value, err
}
return value, nil
}

0 comments on commit 9fcbe3c

Please sign in to comment.