We use cron package in our typescript project. The pattern of usage I see is as follows:
function jobUpdateVerStat() { // defined };
jobExecuteHourly = new CronJob('0 1 * * * *', jobUpdateVerStat);
I needed to pass an argument sess to jobUpdateVerStat. Since this didn't work
const sess = getSess();
jobExecuteHourly = new CronJob('0 1 * * * *', jobUpdateVerStat(sess));
I looked at Cronjob's constructor which looks like this
constructor(cronTime: string | Date | Moment, onTick: CronCommand (..some more parameter..))
CronCommand's declared type is like this
export declare type CronCommand = (() => void) | string | { command: string, args?: ReadonlyArray<string>, options?: SpawnOptions};
So I tried the following based on this information, but none seems to work... Does this just mean that the package doesn't support scheduled run of function with parameter? Is it normally not desired to pass an argument to cronjob or am I missing an obvious hint to make this work?
// function updateVersionStatus(sess) was properly defined
const sess = await createBotSess();
let job1: CronJob;
let job2: CronJob;
job1 = new CronJob('0 */1 * * * *', {
command: 'updateVersionStatus',
args: ['sess'],
});
job2 = new CronJob('0 */1 * * * *', 'updateVersionStatus(sess)');