Skip to content

Commit e3306a6

Browse files
joshkelAbhiPrasad
authored andcommitted
fix(node): Time zone handling for cron (#11225)
The `cron` package uses `timeZone`, while Sentry internally uses `timezone`. This caused Sentry cron jobs to be incorrectly upserted with no time zone information. Because of the use of the `...(timeZone ? { timeZone } : undefined)` idiom, TypeScript type checking did not catch the mistake. I kept `cron`'s `timeZone` capitalization within Sentry's instrumentation and changed from the `...(timeZone ? { timeZone } : undefined)` idiom so TypeScript could catch mistakes of this sort. (Passing an undefined `timezone` appears to be okay, because Sentry's `node-cron` instrumentation does it.)
1 parent bf4ea76 commit e3306a6

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

packages/node/src/cron/cron.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export function instrumentCron<T>(lib: T & CronJobConstructor, monitorSlug: stri
100100
},
101101
{
102102
schedule: { type: 'crontab', value: cronString },
103-
...(timeZone ? { timeZone } : {}),
103+
timezone: timeZone || undefined,
104104
},
105105
);
106106
}
@@ -132,7 +132,7 @@ export function instrumentCron<T>(lib: T & CronJobConstructor, monitorSlug: stri
132132
},
133133
{
134134
schedule: { type: 'crontab', value: cronString },
135-
...(timeZone ? { timeZone } : {}),
135+
timezone: timeZone || undefined,
136136
},
137137
);
138138
};

packages/node/test/cron.test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,20 @@ describe('cron check-ins', () => {
5353

5454
const CronJobWithCheckIn = cron.instrumentCron(CronJobMock, 'my-cron-job');
5555

56-
new CronJobWithCheckIn('* * * Jan,Sep Sun', () => {
57-
expect(withMonitorSpy).toHaveBeenCalledTimes(1);
58-
expect(withMonitorSpy).toHaveBeenLastCalledWith('my-cron-job', expect.anything(), {
59-
schedule: { type: 'crontab', value: '* * * 1,9 0' },
60-
});
61-
done();
62-
});
56+
new CronJobWithCheckIn(
57+
'* * * Jan,Sep Sun',
58+
() => {
59+
expect(withMonitorSpy).toHaveBeenCalledTimes(1);
60+
expect(withMonitorSpy).toHaveBeenLastCalledWith('my-cron-job', expect.anything(), {
61+
schedule: { type: 'crontab', value: '* * * 1,9 0' },
62+
timezone: 'America/Los_Angeles',
63+
});
64+
done();
65+
},
66+
undefined,
67+
true,
68+
'America/Los_Angeles',
69+
);
6370
});
6471

6572
test('CronJob.from()', done => {

0 commit comments

Comments
 (0)