Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(workflows-sdk): additional properties to context #6760

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-bikes-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/workflows-sdk": patch
---

Added idempotencyKey to workflow step context
10 changes: 10 additions & 0 deletions packages/workflows-sdk/src/utils/composer/create-step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ function applyStep<
const handler = {
invoke: async (transactionContext) => {
const executionContext: StepExecutionContext = {
workflowId: transactionContext.model_id,
stepName: transactionContext.action,
action: "invoke",
idempotencyKey: transactionContext.idempotency_key,
attempt: transactionContext.attempt,
container: transactionContext.container,
metadata: transactionContext.metadata,
context: transactionContext.context,
Expand All @@ -148,6 +153,11 @@ function applyStep<
compensate: compensateFn
? async (transactionContext) => {
const executionContext: StepExecutionContext = {
workflowId: transactionContext.model_id,
stepName: transactionContext.action,
action: "compensate",
idempotencyKey: transactionContext.idempotency_key,
attempt: transactionContext.attempt,
container: transactionContext.container,
metadata: transactionContext.metadata,
context: transactionContext.context,
Expand Down
5 changes: 5 additions & 0 deletions packages/workflows-sdk/src/utils/composer/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export function hook<TOutput>(
return {
__value: async function (transactionContext) {
const executionContext: StepExecutionContext = {
workflowId: transactionContext.model_id,
stepName: transactionContext.action,
action: transactionContext.action_type,
idempotencyKey: transactionContext.idempotency_key,
attempt: transactionContext.attempt,
container: transactionContext.container,
metadata: transactionContext.metadata,
context: transactionContext.context,
Expand Down
25 changes: 25 additions & 0 deletions packages/workflows-sdk/src/utils/composer/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ export type CreateWorkflowComposerContext = {
* The step's context.
*/
export interface StepExecutionContext {
/**
* The ID of the workflow.
*/
workflowId: string

/**
* The attempt number of the step.
*/
attempt: number

/**
* The idempoency key of the step.
*/
idempotencyKey: string

/**
* The name of the step.
*/
stepName: string

/**
* The action of the step.
*/
action: "invoke" | "compensate"

/**
* The container used to access resources, such as services, in the step.
*/
Expand Down
Loading