1 export const metadata = {
2 title: `${pageNumber} Scheduled Job Number of Executions`,
3 }
4
5 # {metadata.title}
6
7 In this chapter, you'll learn how to set a limit on the number of times a scheduled job is executed.
8
9 ## Default Number of Scheduled Job Executions
10
11 By default, a scheduled job is executed whenever it matches its specified pattern. For example, if you set a scheduled job to run every five minutes, it will run every five minutes until you stop the Medusa application.
12
13 ---
14
15 ## Configure Number of Scheduled Job Executions
16
17 To execute a scheduled job a specific number of times only, you can configure it with the `numberOfExecutions` option. Its value is the number of times the scheduled job can be executed during the Medusa application's runtime.
18
19 For example:
20
21 export const highlights = [
22 ["9", "numberOfExecutions", "The number of times the job should be executed."]
23 ]
24
25 ```ts highlights={highlights}
26 export default async function myCustomJob() {
27 console.log("I'll be executed only three times.")
28 }
29
30 export const config = {
31 name: "hello-world",
32 // execute every minute
33 schedule: "* * * * *",
34 numberOfExecutions: 3,
35 }
36 ```
37
38 The above scheduled job has the `numberOfExecutions` configuration set to `3`.
39
40 So, Medusa will execute this job only 3 times, once every minute, and then it won't be executed anymore during the current runtime.
41
42 ### Configuration is Per Application Runtime
43
44 Medusa tracks the number of executions for a scheduled job during its current runtime. Once the application stops, the next time you start it, the counter will be reset to `0`.
45
46 So, if you restart the Medusa application, the scheduled job will be executed again until it reaches the number of executions specified.