|
1
|
--- |
|
2
|
sidebar_label: "scheduled-job-default-export-async" |
|
3
|
--- |
|
4
|
|
|
5
|
export const metadata = { |
|
6
|
title: `scheduled-job-default-export-async - ESLint plugin rules`, |
|
7
|
} |
|
8
|
|
|
9
|
# {metadata.title} |
|
10
|
|
|
11
|
This rule requires the default-exported scheduled job function to be async. |
|
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 default-exported scheduled job that isn't an async function. |
|
20
|
|
|
21
|
The following code is reported by the rule: |
|
22
|
|
|
23
|
```ts title="src/jobs/sync-products.ts" |
|
24
|
export default function syncProducts() {} |
|
25
|
``` |
|
26
|
|
|
27
|
Instead, make the job function async: |
|
28
|
|
|
29
|
```ts title="src/jobs/sync-products.ts" |
|
30
|
export default async function syncProducts() {} |
|
31
|
``` |
|
32
|
|
|
33
|
## Why it's Important |
|
34
|
|
|
35
|
Scheduled jobs receive the Medusa container and are always awaited by Medusa. Making the job async ensures Medusa can wait for its work to finish before continuing. |
|
36
|
|
|
37
|
Learn more in the [Scheduled Jobs documentation](!docs!/learn/fundamentals/scheduled-jobs). |
|
38
|
|
|
39
|
## Fixable |
|
40
|
|
|
41
|
This rule is auto-fixable. Run the linter with the `--fix` option to apply the fix automatically. |