backend-tasks: update usage of cron

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-05-27 10:50:44 +02:00
parent f7146b516f
commit c174dc8312
2 changed files with 5 additions and 4 deletions
@@ -123,7 +123,7 @@ export class LocalTaskWorker {
let dt: number;
if (isCron) {
const nextRun = +new CronTime(settings.cadence).sendAt().toDate();
const nextRun = +new CronTime(settings.cadence).sendAt().toJSDate();
dt = nextRun - Date.now();
} else {
dt =
@@ -174,8 +174,9 @@ export class TaskWorker {
} else if (isCron) {
const time = new CronTime(settings.cadence)
.sendAt()
.add({ seconds: -1 }) // immediately, if "* * * * * *"
.toISOString();
.minus({ seconds: 1 }) // immediately, if "* * * * * *"
.toUTC()
.toISO();
startAt = this.knex.client.config.client.includes('sqlite3')
? this.knex.raw('datetime(?)', [time])
: this.knex.raw(`?`, [time]);
@@ -278,7 +279,7 @@ export class TaskWorker {
let nextRun: Knex.Raw;
if (isCron) {
const time = new CronTime(settings.cadence).sendAt().toISOString();
const time = new CronTime(settings.cadence).sendAt().toUTC().toISO();
this.logger.debug(`task: ${this.taskId} will next occur around ${time}`);
nextRun = this.knex.client.config.client.includes('sqlite3')
? this.knex.raw('datetime(?)', [time])