Skip to content

Commit b28e7ec

Browse files
committed
refactor(workflows): adjust cron schedules based on environment
Move environment check to utils module and update workflow schedules to run hourly in production and every minute in development Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com>
1 parent 2336dd2 commit b28e7ec

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/payload.config.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import { collections } from '@/collections'
1111
import { globals } from '@/globals'
1212
import { tasks } from '@/tasks'
1313
import { workflows } from '@/workflows'
14+
import { isProd } from '@/utils/utils'
1415

1516
const filename = fileURLToPath(import.meta.url)
1617
const dirname = path.dirname(filename)
17-
const isProd = process.env.NODE_ENV === 'production'
1818

1919
export default buildConfig({
2020
admin: {
@@ -49,10 +49,9 @@ export default buildConfig({
4949
tasks,
5050
workflows,
5151
autoRun: [
52-
// TODO:(@kelvinkipruto): Use correct schedule.This is for testing only
5352
{
54-
cron: '* * * * *',
55-
queue: 'everyMinute',
53+
cron: isProd ? '0 * * * *' : '* * * * *',
54+
queue: isProd ? 'hourly' : 'everyMinute',
5655
},
5756
],
5857
},

src/utils/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const isProd = process.env.NODE_ENV === 'production'

src/workflows/airtableWorkflow.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { WorkflowConfig } from 'payload'
22
import { randomUUID } from 'node:crypto'
3+
import { isProd } from '@/utils/utils'
34

45
export const airtableWorkflow: WorkflowConfig = {
56
slug: 'airtableWorkflow',
67
label: 'Airtable Workflow',
78
schedule: [
89
{
9-
cron: '* * * * *',
10-
queue: 'everyMinute',
10+
cron: isProd ? '0 * * * *' : '* * * * *',
11+
queue: isProd ? 'hourly' : 'everyMinute',
1112
},
1213
],
1314
handler: async ({ tasks }) => {

0 commit comments

Comments
 (0)