-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32e64b3
commit de88312
Showing
6 changed files
with
185 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const Command = require('../command'); | ||
const { | ||
COMMAND_STATUS, | ||
FINALIZED_COMMAND_CLEANUP_TIME_MILLS, | ||
} = require('../../constants/constants'); | ||
|
||
/** | ||
* Increases approval for Bidding contract on blockchain | ||
*/ | ||
class CommandsCleanerCommand extends Command { | ||
constructor(ctx) { | ||
super(ctx); | ||
this.logger = ctx.logger; | ||
this.repositoryModuleManager = ctx.repositoryModuleManager; | ||
} | ||
|
||
/** | ||
* Executes command and produces one or more events | ||
* @param command | ||
*/ | ||
async execute() { | ||
await this.repositoryModuleManager.removeFinalizedCommands([ | ||
COMMAND_STATUS.COMPLETED, | ||
COMMAND_STATUS.FAILED, | ||
COMMAND_STATUS.EXPIRED, | ||
]); | ||
return Command.repeat(); | ||
} | ||
|
||
/** | ||
* Recover system from failure | ||
* @param command | ||
* @param error | ||
*/ | ||
async recover(command, error) { | ||
this.logger.warn(`Failed to clean finalized commands: error: ${error.message}`); | ||
return Command.repeat(); | ||
} | ||
|
||
/** | ||
* Builds default command | ||
* @param map | ||
* @returns {{add, data: *, delay: *, deadline: *}} | ||
*/ | ||
default(map) { | ||
const command = { | ||
name: 'commandsCleanerCommand', | ||
data: {}, | ||
period: FINALIZED_COMMAND_CLEANUP_TIME_MILLS, | ||
transactional: false, | ||
}; | ||
Object.assign(command, map); | ||
return command; | ||
} | ||
} | ||
|
||
module.exports = CommandsCleanerCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const Command = require('../command'); | ||
const constants = require('../../constants/constants'); | ||
|
||
/** | ||
* Increases approval for Bidding contract on blockchain | ||
*/ | ||
class OperationIdCleanerCommand extends Command { | ||
constructor(ctx) { | ||
super(ctx); | ||
this.logger = ctx.logger; | ||
this.repositoryModuleManager = ctx.repositoryModuleManager; | ||
} | ||
|
||
/** | ||
* Executes command and produces one or more events | ||
* @param command | ||
*/ | ||
async execute() { | ||
const timeToBeDeleted = Date.now() - constants.OPERATION_ID_COMMAND_CLEANUP_TIME_MILLS; | ||
await this.repositoryModuleManager.removeOperationIdRecord(timeToBeDeleted, [ | ||
constants.OPERATION_ID_STATUS.COMPLETED, | ||
constants.OPERATION_ID_STATUS.FAILED, | ||
]); | ||
return Command.repeat(); | ||
} | ||
|
||
/** | ||
* Recover system from failure | ||
* @param command | ||
* @param error | ||
*/ | ||
async recover(command, error) { | ||
this.logger.warn(`Failed to clean operation ids table: error: ${error.message}`); | ||
return Command.repeat(); | ||
} | ||
|
||
/** | ||
* Builds default command | ||
* @param map | ||
* @returns {{add, data: *, delay: *, deadline: *}} | ||
*/ | ||
default(map) { | ||
const command = { | ||
name: 'operationIdCleanerCommand', | ||
period: constants.OPERATION_ID_COMMAND_CLEANUP_TIME_MILLS, | ||
data: {}, | ||
transactional: false, | ||
}; | ||
Object.assign(command, map); | ||
return command; | ||
} | ||
} | ||
|
||
module.exports = OperationIdCleanerCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters