UUID Generation?

Hi,

I was wondering if golang sdk has a UUID generation util like the temporal java sdk? I recall it was recommended to use if it’s called within a workflow to be deterministic. I wasn’t sure if this rule applied to golang for generating uuid.

From the sample-go project, there is a workflow test that uses github.com/google/uuid. This make me think that it doesn’t matter?

Thanks
Derek

Use SideEffect to generate UUID in Go workflows.

Thanks, that was what i was looking for. However, i’m running into the following error

{
  "message": "No cached result found for side effectID=6. KnownSideEffects=[]",
  "source": "GoSDK",
  "stackTrace": "coroutine root [panic]:\ngo.temporal.io/sdk/internal.(*workflowEnvironmentImpl).SideEffect(0x140002ffa40, 0x140012a7680, 0x140012a76b0)\n\t/go/pkg/mod/go.temporal.io/sdk@v1.21.1/internal/internal_event_handlers.go:758 +0x560\ngo.temporal.io/sdk/internal.(*workflowEnvironmentInterceptor).SideEffect(0x140012a0410, {0x105bacfa8, 0x140012a7020}, 0x105b6d610)\n\t/=/go/pkg/mod/go.temporal.io/sdk@v1.21.1/internal/workflow.go:1465 +0x208\ngo.temporal.io/sdk/internal.SideEffect({0x105bacfa8, 0x140012a7020}, 0x105b6d610)\n\t/go/pkg/mod/go.temporal.io/sdk@v1.21.1/internal/workflow.go:1452 +0x60\ngo.temporal.io/sdk/workflow.SideEffect({0x105bacfa8, 0x140012a7020}, 0x105b6d610)\n\t/go/pkg/mod/go.temporal.io/sdk@v1.21.1/workflow/workflow.go:284 ...,
  "encodedAttributes": null,
  "cause": null,
  "applicationFailureInfo": {
    "type": "PanicError",
    "nonRetryable": true,
    "details": null
  }
}

Here is a snapshot of the history. It registers a side effect for each time the UUID is generated which seems to make sense.

when i open the payload side effect id 6 which the error is referring to, it’s not clear what the issue really is…

Any idea whats going on? I followed Go SDK developer's guide - Features | Temporal Documentation


func (p *PdFrameworkWorkflow) GeneratedUUID(ctx workflow.Context) string {
	encodedUUID := workflow.SideEffect(ctx, func(ctx workflow.Context) interface{} {
		return uuid.New().String()
	})

	var uuid string
	encodedUUID.Get(&uuid)
	return uuid
}

This method is being called by the workflow and passes in the workflow context. It’s called multiple times in the workflow function to generate a unique UUID.

Any idea what i’m doing wrong?
Thanks!

Actually, this might not be an issue anymore. I think the error isn’t reflecting the new workflows i’m creating with the updated worker code that supports side-effect, but rather based on the old workflows that executed/terminated against the old worker code without the side-effect in place.

Because I don’t know how to clear the workflow history, any query calls to this terminated workflows can caused these error messages.

Just curious, would it be make sense to not include the SideEffect in the compact view?

You have to use versioning to update workflow code if there are open workflows.

Just curious, would it be make sense to not include the SideEffect in the compact view?

Fully agree. We are working on completely revamping the UI views of the workflows.

In these case, if the workflow is terminated isn’t that considered closed workflows.

I believe you can still query closed workflows for state no? In that case if the worker code changes, wouldn’t that result in issues as well?

Also is it possible to delete specific workflow entries from the workflow history?

In these case, if the workflow is terminated isn’t that considered closed workflows.

I don’t think you can query terminated workflows as they are considered in a non defined state after termination.

I believe you can still query closed workflows for state no? In that case if the worker code changes, wouldn’t that result in issues as well?

Even if the query goes through the code change without versioning might lead to failures to replay workflow.

Also is it possible to delete specific workflow entries from the workflow history?

History is immutable. You can reset workflow to some point in the history. But it will continue executing after that point.