async scheduleTask(task) {
    this.context.log.i('Scheduler scheduleTask: ' + util.inspect(task, { showHidden: true, depth: 6 }));
    let timeDiff = this.getNextExecutionTimeDiff(task);

    if (timeDiff > 0) {
      this.context.log.i('Scheduler scheduleTask: task.id: ' + task.id + '; timeDiff: ' + timeDiff);
      const taskArgument = { task, scheduler: this };
      if (timeDiff >= OhUtils.MAX_TIMEOUT - MaxIntervalSafetyGap) {
        this.context.log.i(
          'Scheduler scheduleTask: task.id: ' +
            task.id +
            '; timeDiff: ' +
            timeDiff +
            '; timeDiff overflow. Postponing the schedule.'
        );
        taskArgument.reschedule = true;
        timeDiff = OhUtils.MAX_TIMEOUT - MaxIntervalSafetyGap;
      }

      task.timeoutHandle = setTimeout(
        taskArg => {
          if (taskArg.reschedule === true) {
            taskArg.scheduler.scheduleTask(taskArg.task);
          } else {
            taskArg.scheduler.executeTask(taskArg.task);
          }
        },
        timeDiff,
        taskArgument
      );
    } else {
      this.context.log.i(
        'Scheduler scheduleTask: task.id: ' + task.id + '; timeDiff: ' + timeDiff + '; scheduled in the past, removing.'
      );

      await this.deleteTask(task);
    }
  }
/**
   * Schedules a task using setTimeout/cancelTimeout API. If the task is one-shot and scheduled in the past,
   * then removes it. If the task is recurrent - schedules it at the nearest appropriate time.
   * If scheduled too far in the future, schedules a reschedulement at the max interval
   * acceptable by the setTimeout funcction (minus some safety gap to avoid jumping over the scheduled timeout
   * due to CPU busy with other tasks).
   * @param  {OrgTask} task the task to be scheduled
   * @return {Promise}      nothing
   */
Schedules a task using setTimeout/cancelTimeout API. If the task is one-shot and scheduled in the past,
then removes it. If the task is recurrent - schedules it at the nearest appropriate time.
If scheduled too far in the future, schedules a reschedulement at the max interval
acceptable by the setTimeout funcction (minus some safety gap to avoid jumping over the scheduled timeout
due to CPU busy with other tasks).
@param  {OrgTask} task the task to be scheduled
@return {Promise}      nothing
Schedules a task using setTimeout / cancelTimeout API . If the task is one - shot and scheduled in the past then removes it . If the task is recurrent - schedules it at the nearest appropriate time . If scheduled too far in the future schedules a reschedulement at the max interval acceptable by the setTimeout funcction ( minus some safety gap to avoid jumping over the scheduled timeout due to CPU busy with other tasks ) . @param { OrgTask } task the task to be scheduled @return { Promise } nothing
async scheduleTask(task) {
    this.context.log.i('Scheduler scheduleTask: ' + util.inspect(task, { showHidden: true, depth: 6 }));
    let timeDiff = this.getNextExecutionTimeDiff(task);
    if (timeDiff > 0) {
      this.context.log.i('Scheduler scheduleTask: task.id: ' + task.id + '; timeDiff: ' + timeDiff);
      const taskArgument = { task, scheduler: this };
      if (timeDiff >= OhUtils.MAX_TIMEOUT - MaxIntervalSafetyGap) {
        this.context.log.i(
          'Scheduler scheduleTask: task.id: ' +
            task.id +
            '; timeDiff: ' +
            timeDiff +
            '; timeDiff overflow. Postponing the schedule.'
        );
        taskArgument.reschedule = true;
        timeDiff = OhUtils.MAX_TIMEOUT - MaxIntervalSafetyGap;
      }
      task.timeoutHandle = setTimeout(
        taskArg => {
          if (taskArg.reschedule === true) {
            taskArg.scheduler.scheduleTask(taskArg.task);
          } else {
            taskArg.scheduler.executeTask(taskArg.task);
          }
        },
        timeDiff,
        taskArgument
      );
    } else {
      this.context.log.i(
        'Scheduler scheduleTask: task.id: ' + task.id + '; timeDiff: ' + timeDiff + '; scheduled in the past, removing.'
      );
      await this.deleteTask(task);
    }
  }
async scheduleTask ( task ) { this . context . log . i ( 'Scheduler scheduleTask: ' + util . inspect ( task , { showHidden : true , depth : 6 } ) ) ; let timeDiff = this . getNextExecutionTimeDiff ( task ) ; if ( timeDiff > 0 ) { this . context . log . i ( 'Scheduler scheduleTask: task.id: ' + task . id + '; timeDiff: ' + timeDiff ) ; const taskArgument = { task , scheduler : this } ; if ( timeDiff >= OhUtils . MAX_TIMEOUT - MaxIntervalSafetyGap ) { this . context . log . i ( 'Scheduler scheduleTask: task.id: ' + task . id + '; timeDiff: ' + timeDiff + '; timeDiff overflow. Postponing the schedule.' ) ; taskArgument . reschedule = true ; timeDiff = OhUtils . MAX_TIMEOUT - MaxIntervalSafetyGap ; } task . timeoutHandle = setTimeout ( taskArg => { if ( taskArg . reschedule === true ) { taskArg . scheduler . scheduleTask ( taskArg . task ) ; } else { taskArg . scheduler . executeTask ( taskArg . task ) ; } } , timeDiff , taskArgument ) ; } else { this . context . log . i ( 'Scheduler scheduleTask: task.id: ' + task . id + '; timeDiff: ' + timeDiff + '; scheduled in the past, removing.' ) ; await this . deleteTask ( task ) ; } }
Schedules a task using setTimeout/cancelTimeout API.
Schedules a task using setTimeout / cancelTimeout API .