Scheduled Jobs Number of Executions

In this chapter, you'll learn how to set a limit on the number of times a scheduled job is executed.

numberOfExecutions Option#

The export configuration object of the scheduled job accepts an optional property numberOfExecutions. Its value is a number indicating how many times the scheduled job can be executed during the Medusa application's runtime.

For example:

Code
1export default async function myCustomJob() {2  console.log("I'll be executed three times only.")3}4
5export const config = {6  name: "hello-world",7  // execute every minute8  schedule: "* * * * *",9  numberOfExecutions: 3,10}

The above scheduled job has the numberOfExecutions configuration set to 3.

So, it'll only execute 3 times, each every minute, then it won't be executed anymore.

NoteIf you restart the Medusa application, the scheduled job will be executed again until reaching the number of executions specified.
Was this chapter helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break