|
1
|
--- |
|
2
|
sidebar_label: "scheduled-job-default-export-required" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `scheduled-job-default-export-required - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule requires scheduled job files to default-export the job function. |
|
12
|
|
|
13
|
## Severity |
|
14
|
|
|
15
|
`error`. This rule is enabled in the [recommended](../../page.mdx#recommended) preset. |
|
16
|
|
|
17
|
## What it Targets |
|
18
|
|
|
19
|
This rule targets files in your project's `src/jobs` directory. It reports a scheduled job file that has no default export. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```ts title="src/jobs/sync-products.ts" |
|
24
|
export const syncProducts = async () => {} |
|
25
|
``` |
|
26
|
|
|
27
|
Instead, default-export the async job function: |
|
28
|
|
|
29
|
```ts title="src/jobs/sync-products.ts" |
|
30
|
export default async function syncProducts() {} |
|
31
|
|
|
32
|
export const config = { |
|
33
|
name: "sync-products", |
|
34
|
schedule: "0 0 * * *", |
|
35
|
} |
|
36
|
``` |
|
37
|
|
|
38
|
## Why it's Important |
|
39
|
|
|
40
|
Medusa registers and runs the job's default export on its schedule. Without a default export, the job never runs. |
|
41
|
|
|
42
|
Learn more in the [Scheduled Jobs documentation](!docs!/learn/fundamentals/scheduled-jobs). |
|
43
|
|
|
44
|
## Fixable |
|
45
|
|
|
46
|
This rule isn't auto-fixable. |