-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ref: Remove some unnecessary conditions #14698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ describe('makeMultiplexedTransport', () => { | |
const makeTransport = makeMultiplexedTransport( | ||
createTestTransport((url, _, env) => { | ||
expect(url).toBe(DSN2_URL); | ||
expect(env[0]?.dsn).toBe(DSN2); | ||
expect(env[0].dsn).toBe(DSN2); | ||
}), | ||
() => [DSN2], | ||
); | ||
|
@@ -134,7 +134,7 @@ describe('makeMultiplexedTransport', () => { | |
createTestTransport((url, release, env) => { | ||
expect(url).toBe(DSN2_URL); | ||
expect(release).toBe('[email protected]'); | ||
expect(env[0]?.dsn).toBe(DSN2); | ||
expect(env[0].dsn).toBe(DSN2); | ||
}), | ||
() => [{ dsn: DSN2, release: '[email protected]' }], | ||
); | ||
|
@@ -150,7 +150,7 @@ describe('makeMultiplexedTransport', () => { | |
createTestTransport((url, release, env) => { | ||
expect(url).toBe('http://google.com'); | ||
expect(release).toBe('[email protected]'); | ||
expect(env[0]?.dsn).toBe(DSN2); | ||
expect(env[0].dsn).toBe(DSN2); | ||
}), | ||
() => [{ dsn: DSN2, release: '[email protected]' }], | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ export interface NodeCronOptions { | |
} | ||
|
||
export interface NodeCron { | ||
schedule: (cronExpression: string, callback: () => void, options: NodeCronOptions) => unknown; | ||
schedule: (cronExpression: string, callback: () => void, options: NodeCronOptions | undefined) => unknown; | ||
} | ||
|
||
/** | ||
|
@@ -30,20 +30,23 @@ export interface NodeCron { | |
*/ | ||
export function instrumentNodeCron<T>(lib: Partial<NodeCron> & T): T { | ||
return new Proxy(lib, { | ||
get(target, prop: keyof NodeCron) { | ||
get(target, prop) { | ||
if (prop === 'schedule' && target.schedule) { | ||
// When 'get' is called for schedule, return a proxied version of the schedule function | ||
return new Proxy(target.schedule, { | ||
apply(target, thisArg, argArray: Parameters<NodeCron['schedule']>) { | ||
const [expression, callback, options] = argArray; | ||
|
||
if (!options?.name) { | ||
const name = options?.name; | ||
const timezone = options?.timezone; | ||
|
||
if (!name) { | ||
throw new Error('Missing "name" for scheduled job. A name is required for Sentry check-in monitoring.'); | ||
} | ||
|
||
async function monitoredCallback(): Promise<void> { | ||
const monitoredCallback = async (): Promise<void> => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AbhiPrasad (I think you worked on this initially) is it important that this is not an arrow function? Without this, it complains about stuff being mutateable as this is hoisted, I guess. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. arrow function should be fine, it shouldn't rely on the |
||
return withMonitor( | ||
options.name, | ||
name, | ||
async () => { | ||
// We have to manually catch here and capture the exception because node-cron swallows errors | ||
// https://github.com/node-cron/node-cron/issues/399 | ||
|
@@ -56,16 +59,16 @@ export function instrumentNodeCron<T>(lib: Partial<NodeCron> & T): T { | |
}, | ||
{ | ||
schedule: { type: 'crontab', value: replaceCronNames(expression) }, | ||
timezone: options?.timezone, | ||
timezone, | ||
}, | ||
); | ||
} | ||
}; | ||
|
||
return target.apply(thisArg, [expression, monitoredCallback, options]); | ||
}, | ||
}); | ||
} else { | ||
return target[prop]; | ||
return target[prop as keyof T]; | ||
} | ||
}, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of this is try-catched anyhow.