Skip to content

Commit 1ca0622

Browse files
committed
refactor: cron plugin
1 parent d5e8107 commit 1ca0622

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

apps/cron/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ARG TURBO_TOKEN
2727
ENV TURBO_TOKEN=${TURBO_TOKEN}
2828

2929
ARG TURBO_REMOTE_CACHE_SIGNATURE_KEY
30-
ENV TURBO_REMOTE_CACHE_SIGNATURE_KEY=${TURBO_REMOTE_CACHE_SIGNATURE_KEY}
30+
ENV TURBO_REMOTE_CACHE_SIGNATURE_KEY=$TURBO_REMOTE_CACHE_SIGNATURE_KEY
3131

3232
ENV APP_NAME="cron"
3333
ENV APP_DIR="apps/${APP_NAME}"

apps/cron/src/common/plugins/global/cronPlugin.mts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,21 @@ const cronPlugin: FastifyPluginAsync = async (fastfiy) => {
9090
}
9191

9292
const initializeJobs = async () => {
93+
console.log('Initializing cron jobs...')
9394
if (ENV.appEnv !== 'production') {
94-
console.log('start')
95-
const immediateRunJobs = jobDescription.filter((job) => !!job.isImmediateExecute)
96-
await Promise.all(immediateRunJobs.map(createTick))
97-
const crons = immediateRunJobs.map(createJob)
95+
const immediateRunJobs = jobDescription.filter((job) => job.isImmediateExecute)
96+
const crons = await Promise.all(immediateRunJobs.map(createJob))
9897
for (const cron of crons) {
99-
console.log(`${cron.name} is registered`)
10098
cron.start()
99+
console.log(`${cron.name} is registered`)
101100
}
102101
}
103102

104-
if (ENV.dockerEnv === 'production') {
105-
const crons = jobDescription.map(createJob)
103+
if (['production', 'stage'].includes(ENV.dockerEnv)) {
104+
const crons = await Promise.all(jobDescription.map(createJob))
106105
for (const cron of crons) {
107-
console.log(`${cron.name} is registered`)
108106
cron.start()
107+
console.log(`${cron.name} is registered`)
109108
}
110109
}
111110
}

infrastructure/Pulumi.production.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
config:
22
aws:region: ap-northeast-2
33
velog:DOCKER_ENV: production
4-
velog:target: server
4+
velog:target: cron

infrastructure/Pulumi.stage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
config:
22
aws:region: ap-northeast-2
33
velog:DOCKER_ENV: stage
4-
velog:target: server
4+
velog:target: cron

0 commit comments

Comments
 (0)