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): run, registerStepSuccess and registerStepFailure shortcut #6164

Merged
merged 9 commits into from
Jan 22, 2024

Conversation

adrien2p
Copy link
Member

@adrien2p adrien2p commented Jan 22, 2024

What

Currently, when exporting a workflow using the workflowExport util, it is mandatory to first call the resulted function passing the container before being able to call run, registerStepSuccess or failure on it. Now, it is possible to either continue that way, or to directly call the run, registerStepSuccess or failure on the exported workflow and at that moment it is possible to pass a container if needed

e.g

const workflow = exportWorkflow("id" as any, "result_step", prepare)
const wfRunner = workflow(container)
wfRunner.run(...) // Here the container is not expected

or

const workflow = exportWorkflow("id" as any, "result_step", prepare)
workflow.run(...) // Here we can now pass an optional container 

Copy link

changeset-bot bot commented Jan 22, 2024

🦋 Changeset detected

Latest commit: 8ab1a56

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@medusajs/workflows-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-reference 🔄 Building (Inspect) Visit Preview Jan 22, 2024 6:49pm
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 22, 2024 6:49pm
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
docs-ui ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2024 6:49pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Jan 22, 2024 6:49pm

@adrien2p
Copy link
Member Author

@adrien2p adrien2p marked this pull request as ready for review January 22, 2024 15:00
@adrien2p adrien2p requested review from a team as code owners January 22, 2024 15:00
Copy link
Contributor

@carlos-r-l-rodrigues carlos-r-l-rodrigues left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adrien2p
Copy link
Member Author

@carlos-r-l-rodrigues do you think I should merge so that I can include it in our pr?

@olivermrbl
Copy link
Contributor

olivermrbl commented Jan 22, 2024

I would love to give it a spin 👍

@adrien2p
Copy link
Member Author

adrien2p commented Jan 22, 2024

@olivermrbl sure, you can look at the tests to see the usage. But at somepoint everything will go through the engine, so it will always go through the enigine run method which among other things accept the container as part of the options 👍

@olivermrbl
Copy link
Contributor

This is great!

And if there's no container, it will try to use the loaded modules under the hood right?

So for example:

const createSomething = createSomethingWorkflow()

const { result, errors } = await createSomething.run({
  input: { ... }
})

@adrien2p
Copy link
Member Author

adrien2p commented Jan 22, 2024

yes, or you can do

// Here it will use the loaded modules
const { result, errors } = await createSomethingWorkflow.run({
  input: { ... }
})

no need for the first step

@olivermrbl
Copy link
Contributor

Love it 😍

@carlos-r-l-rodrigues
Copy link
Contributor

carlos-r-l-rodrigues commented Jan 22, 2024

We have to support both ways:

const wf = myWorkflow();
wf.run({})

and

myWorkflow.run({})

The first one is an instance of LocalWorkflows that is the only way you can extend it.

const wf = myWorkflow();
wf.addStep(...)
wf.run({})

@olivermrbl
Copy link
Contributor

@carlos-r-l-rodrigues, makes sense!

@kodiakhq kodiakhq bot merged commit 738e911 into develop Jan 22, 2024
16 checks passed
@kodiakhq kodiakhq bot deleted the feat/workflows-sdk-shortcut branch January 22, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants