temporalio / features

Behavior and history compatibility testing for Temporal SDKs
13 stars 17 forks source link

[Feature Request] Expose UpdateID in an update handler #293

Open Quinn-With-Two-Ns opened 1 year ago

Quinn-With-Two-Ns commented 1 year ago

Is your feature request related to a problem? Please describe.

Add a way for users to obtain an update requests UpdateID in a handler.

Describe the solution you'd like

In Go I would implement it through Info call like GetUpdateInfo

func Counter(ctx workflow.Context) (int, error) {
    log := workflow.GetLogger(ctx)
    counter := 0

    if err := workflow.SetUpdateHandlerWithOptions(
        ctx,
        FetchAndAdd,
        func(ctx workflow.Context, i int) (int, error) {
                        updateID := workflow.GetUpdateInfo(ctx).UpdateID
            tmp := counter
            counter += i
            log.Info("counter updated", "addend", i, "new-value", counter, "update ID", updateID)
            return tmp, nil
        },
        workflow.UpdateHandlerOptions{Validator: nonNegative},
    ); err != nil {
        return 0, err
    }

Additional context

We should also consider adding UpdateID to the interceptors as well

stephanos commented 9 months ago

Out of curiosity, what's the use case behind this request?

Quinn-With-Two-Ns commented 9 months ago

@stephanos There are multiple use cases for knowing an update ID including for continue as new (see typescript issue https://github.com/temporalio/sdk-typescript/issues/1317), wanting to interact with specific update requests in a workflow (see cancellation POC https://github.com/temporalio/samples-go/pull/297), or the update ID may also have some significance for the business process.