Effect CommunityEC
Effect Community5mo ago
7 replies
adrian_g

Unique Token Generation for Activity Retries in Workflows

I had a use case for creating and awaiting a DurableDeffered inside a Workflow's Activity, which work ok as long as I don't use Activity.retry since the token will be the same on retry, and I need it to be unique to each retry.

I came up with the following to create a token unique to each attempt, but this doesn't work with await, since it assumes executionId from the enclosing workflow

const activityExecutionId = yield* Activity.executionIdWithAttempt
const token = DurableDeferred.tokenFromExecutionId(
  EmailTrigger,
  {
    workflow: EmailWorkflow,
    executionId: activityExecutionId,
  },
)


could we add awaitWithExecutionId to cater for this case?

Or maybe DurableDeferred.token and await should both be aware of Activity.CurrentAttempt and automatically create\await attempt specific token? Although this could lead to gotchas if token is created inside an activity and awaited outside of it,
Was this page helpful?