lib/cargo.js
// check if to commit disk file to clickhouse DB
check if to commit disk file to clickhouse DB
check if to commit disk file to clickhouse DB
async exam() {
      var err, hasRotation;
      try {
        await this.flushToFile();
      } catch (error) {
        err = error;
        debuglog(`[exam ${this.tableName}] ABORT fail to flush. error:`, err);
        return;
      }
      if (!(Date.now() > this.lastCommitAt + this.commitInterval)) {
        return;
      }
      if (!isThisLeader()) {
        debuglog(`[exam ${this.tableName}] CANCLE NOT leadWorkerId`);
        this.lastCommitAt = Date.now() + this.commitInterval * 10;
        return;
      }
      try {
        hasRotation = (await this.rotateFile());
        this.countRotation += Number(hasRotation);
        await this.commitToClickhouseDB();
        this.lastCommitAt = Date.now();
      } catch (error) {
        err = error;
        debuglog(`[exam ${this.tableName}] FAILED to commit. error:`, err);
      }
    }
async exam ( ) { var err , hasRotation ; try { await this . flushToFile ( ) ; } catch ( error ) { err = error ; debuglog ( ` ${ this . tableName } ` , err ) ; return ; } if ( ! ( Date . now ( ) > this . lastCommitAt + this . commitInterval ) ) { return ; } if ( ! isThisLeader ( ) ) { debuglog ( ` ${ this . tableName } ` ) ; this . lastCommitAt = Date . now ( ) + this . commitInterval * 10 ; return ; } try { hasRotation = ( await this . rotateFile ( ) ) ; this . countRotation += Number ( hasRotation ) ; await this . commitToClickhouseDB ( ) ; this . lastCommitAt = Date . now ( ) ; } catch ( error ) { err = error ; debuglog ( ` ${ this . tableName } ` , err ) ; } }
check if to commit disk file to clickhouse DB
check if to commit disk file to clickhouse DB
//debuglog "[exam #{@tableName}] SKIP tick not reach" // non-leader skip 10 commit rounds //debuglog "[exam] LEAD COMMIT" //if hasRotation or @countRotation < 1 // LAZY: commit only when: 1. has local rotated uncommits, or 2. first time exame to cargo to restore any previous local uncommits