I am having a class where I am using node-schedule's bind()
-function to create a job queue:
class Test {
constructor() {}
schedulerLog(value) {
this.ipcRenderer.send('job-log', process.pid + ': ' + value);
}
async initScheduler() {
try {
let dt = new Date(el.scheduled_time)
let db = this.knex // one knex instance per scheduled job
this.schedule.scheduleJob(dt, function () {
// When job is running update the status of the job in the db
let sc = new ScheduledContent(db)
el.status = "sent" // set status to "sent"
sc.createOrUpdateContent(el.id, el.title, null, el.scheduled_time, el.image, el.status).then((res) => {
schedulerLog('Job-ID #' + el.id + ' -- ' + el.title + ' -- executed at: ' + dt + " -- and updated: " + res);
})
}.bind(null, [db, schedulerLog]));
this.schedulerLog("\n Number of Jobs Scheduled: " + Object.keys(this.getQueue()).length + "\n");
} catch (error) {
this.schedulerLog(error);
}
}
}
module.exports = {
Test
};
However, when using .bind(null, [db, schedulerLog])
I get an error:
ReferenceError: schedulerLog is not defined
Any suggestions how I still can bind the function within my class to the queue?
I appreciate your replies!