worker.js
/**
     * Store replay id to DynamoDB if configured, or no-op otherwise.
     * @param {boolean} flush if true the actual Promise would be returned, otherwise Promise.resolve() would be returned.
     * @returns Promise for the save operation or no-op
     */
Store replay id to DynamoDB if configured, or no-op otherwise.
@param {boolean} flush if true the actual Promise would be returned, otherwise Promise.resolve() would be returned.
@returns Promise for the save operation or no-op
Store replay id to DynamoDB if configured or no - op otherwise . @param { boolean } flush if true the actual Promise would be returned otherwise Promise . resolve () would be returned . @returns Promise for the save operation or no - op
storeReplayId(flush) {
        if (this.replayIdStoreTableName) {
            const now = new Date().getTime();
            const moreToWait = this.replayIdStoreDelay - (now - this.lastReplayIdStoredTime);
            if (flush || moreToWait <= 0) {
                const newReplayId = this.replayId;
                const p = this.ddb.update({
                    TableName: this.replayIdStoreTableName,
                    Key: {
                        [this.replayIdStoreKeyName]: this.workerId,
                    },
                    UpdateExpression: "set replayId = :newReplayId",
                    ConditionExpression: `attribute_not_exists(${this.replayIdStoreKeyName}) or attribute_not_exists(replayId) or replayId < :newReplayId`,
                    ExpressionAttributeValues:{
                        ":newReplayId": newReplayId,
                    },
                }).promise()
                .then(result => {
                    this.lastReplayIdStored = newReplayId;
                })
                .catch(e => {
                    this.log(`Didn't store replayId ${newReplayId}: ${e}`);
                });
                return flush? p : Promise.resolve();
            } else {
                setTimeout(this.storeReplayId.bind(this), moreToWait + 100);
            }
        }
        return Promise.resolve();
    }
storeReplayId ( flush ) { if ( this . replayIdStoreTableName ) { const now = new Date ( ) . getTime ( ) ; const moreToWait = this . replayIdStoreDelay - ( now - this . lastReplayIdStoredTime ) ; if ( flush || moreToWait <= 0 ) { const newReplayId = this . replayId ; const p = this . ddb . update ( { TableName : this . replayIdStoreTableName , Key : { [ this . replayIdStoreKeyName ] : this . workerId , } , UpdateExpression : "set replayId = :newReplayId" , ConditionExpression : ` ${ this . replayIdStoreKeyName } ` , ExpressionAttributeValues : { ":newReplayId" : newReplayId , } , } ) . promise ( ) . then ( result => { this . lastReplayIdStored = newReplayId ; } ) . catch ( e => { this . log ( ` ${ newReplayId } ${ e } ` ) ; } ) ; return flush ? p : Promise . resolve ( ) ; } else { setTimeout ( this . storeReplayId . bind ( this ) , moreToWait + 100 ) ; } } return Promise . resolve ( ) ; }
Store replay id to DynamoDB if configured, or no-op otherwise.
Store replay id to DynamoDB if configured or no - op otherwise .
// save to DynamoDb