async syncTasks() {
    const dbTasks = await this.context.dbManager.getRows(this.context.dbManager.tasksTable);

    const foundIndices = [];

    for (let i = dbTasks.length - 1; i >= 0; i--) {
      let found = false;
      for (let j = 0; j < this.tasks.length; j++) {
        if (dbTasks[i].equalsByKey(this.tasks[j])) {
          found = true;
          foundIndices.push(j);
          const valuesToUpdate = dbTasks[i].getValuesToUpdate(this.tasks[j]);

          const fieldsToUpdate = Object.keys(valuesToUpdate);
          if (fieldsToUpdate.length > 0) {
            for (const field of fieldsToUpdate) {
              this.tasks[j][field] = dbTasks[i][field];
            }

            this.context.log.i(
              'Scheduler syncTasks: dbTasks[i]: ' +
                dbTasks[i].id +
                '; updated, new values: ' +
                util.inspect(fieldsToUpdate, { showHidden: true, depth: 6 })
            );
            clearTimeout(this.tasks[j].timeoutHandle);
            await this.scheduleTask(this.tasks[j]);
          }

          break;
        }
      }

      if (!found) {
        this.context.log.i('Scheduler syncTasks: dbTasks[i]: ' + dbTasks[i].id + '; new task detected, adding.');
        this.tasks.push(dbTasks[i]);
        foundIndices.push(this.tasks.length - 1);
        await this.scheduleTask(dbTasks[i]);
      }
    }

    const toDelete = this.tasks.filter((value, index) => {
      return !foundIndices.includes(index);
    });

    this.context.log.d('Scheduler syncTasks: toDelete: ' + util.inspect(toDelete, { showHidden: true, depth: 3 }));
    if (!OhUtils.isEmpty(toDelete)) {
      for (const element of toDelete) {
        for (let j = this.tasks.length - 1; j >= 0; j--) {
          if (element.equalsByKey(this.tasks[j])) {
            this.context.log.i(
              'Scheduler syncTasks: this.tasks[j].id: ' + this.tasks[j].id + ' was removed from DB, cancelling.'
            );
            clearTimeout(this.tasks[j].timeoutHandle);
            this.tasks.splice(j, 1);
          }
        }
      }
    }
  }
/**
   * Updates tasks in RAM according the their DB counterparts. Schedules the new tasks, reschedule updated
   * tasks, cancels deleted tasks.
   * @return {Promise} nothing
   */
Updates tasks in RAM according the their DB counterparts. Schedules the new tasks, reschedule updated
tasks, cancels deleted tasks.
@return {Promise} nothing
Updates tasks in RAM according the their DB counterparts . Schedules the new tasks reschedule updated tasks cancels deleted tasks . @return { Promise } nothing
async syncTasks() {
    const dbTasks = await this.context.dbManager.getRows(this.context.dbManager.tasksTable);
    const foundIndices = [];
    for (let i = dbTasks.length - 1; i >= 0; i--) {
      let found = false;
      for (let j = 0; j < this.tasks.length; j++) {
        if (dbTasks[i].equalsByKey(this.tasks[j])) {
          found = true;
          foundIndices.push(j);
          const valuesToUpdate = dbTasks[i].getValuesToUpdate(this.tasks[j]);
          const fieldsToUpdate = Object.keys(valuesToUpdate);
          if (fieldsToUpdate.length > 0) {
            for (const field of fieldsToUpdate) {
              this.tasks[j][field] = dbTasks[i][field];
            }
            this.context.log.i(
              'Scheduler syncTasks: dbTasks[i]: ' +
                dbTasks[i].id +
                '; updated, new values: ' +
                util.inspect(fieldsToUpdate, { showHidden: true, depth: 6 })
            );
            clearTimeout(this.tasks[j].timeoutHandle);
            await this.scheduleTask(this.tasks[j]);
          }
          break;
        }
      }
      if (!found) {
        this.context.log.i('Scheduler syncTasks: dbTasks[i]: ' + dbTasks[i].id + '; new task detected, adding.');
        this.tasks.push(dbTasks[i]);
        foundIndices.push(this.tasks.length - 1);
        await this.scheduleTask(dbTasks[i]);
      }
    }
    const toDelete = this.tasks.filter((value, index) => {
      return !foundIndices.includes(index);
    });
    this.context.log.d('Scheduler syncTasks: toDelete: ' + util.inspect(toDelete, { showHidden: true, depth: 3 }));
    if (!OhUtils.isEmpty(toDelete)) {
      for (const element of toDelete) {
        for (let j = this.tasks.length - 1; j >= 0; j--) {
          if (element.equalsByKey(this.tasks[j])) {
            this.context.log.i(
              'Scheduler syncTasks: this.tasks[j].id: ' + this.tasks[j].id + ' was removed from DB, cancelling.'
            );
            clearTimeout(this.tasks[j].timeoutHandle);
            this.tasks.splice(j, 1);
          }
        }
      }
    }
  }
async syncTasks ( ) { const dbTasks = await this . context . dbManager . getRows ( this . context . dbManager . tasksTable ) ; const foundIndices = [ ] ; for ( let i = dbTasks . length - 1 ; i >= 0 ; i -- ) { let found = false ; for ( let j = 0 ; j < this . tasks . length ; j ++ ) { if ( dbTasks [ i ] . equalsByKey ( this . tasks [ j ] ) ) { found = true ; foundIndices . push ( j ) ; const valuesToUpdate = dbTasks [ i ] . getValuesToUpdate ( this . tasks [ j ] ) ; const fieldsToUpdate = Object . keys ( valuesToUpdate ) ; if ( fieldsToUpdate . length > 0 ) { for ( const field of fieldsToUpdate ) { this . tasks [ j ] [ field ] = dbTasks [ i ] [ field ] ; } this . context . log . i ( 'Scheduler syncTasks: dbTasks[i]: ' + dbTasks [ i ] . id + '; updated, new values: ' + util . inspect ( fieldsToUpdate , { showHidden : true , depth : 6 } ) ) ; clearTimeout ( this . tasks [ j ] . timeoutHandle ) ; await this . scheduleTask ( this . tasks [ j ] ) ; } break ; } } if ( ! found ) { this . context . log . i ( 'Scheduler syncTasks: dbTasks[i]: ' + dbTasks [ i ] . id + '; new task detected, adding.' ) ; this . tasks . push ( dbTasks [ i ] ) ; foundIndices . push ( this . tasks . length - 1 ) ; await this . scheduleTask ( dbTasks [ i ] ) ; } } const toDelete = this . tasks . filter ( ( value , index ) => { return ! foundIndices . includes ( index ) ; } ) ; this . context . log . d ( 'Scheduler syncTasks: toDelete: ' + util . inspect ( toDelete , { showHidden : true , depth : 3 } ) ) ; if ( ! OhUtils . isEmpty ( toDelete ) ) { for ( const element of toDelete ) { for ( let j = this . tasks . length - 1 ; j >= 0 ; j -- ) { if ( element . equalsByKey ( this . tasks [ j ] ) ) { this . context . log . i ( 'Scheduler syncTasks: this.tasks[j].id: ' + this . tasks [ j ] . id + ' was removed from DB, cancelling.' ) ; clearTimeout ( this . tasks [ j ] . timeoutHandle ) ; this . tasks . splice ( j , 1 ) ; } } } } }
Updates tasks in RAM according the their DB counterparts.
Updates tasks in RAM according the their DB counterparts .