-
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.
Merge branch 'v6/develop' into test/bdd-publish-errors
- Loading branch information
Showing
18 changed files
with
446 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const Command = require('../command'); | ||
const { OPERATION_ID_STATUS, ERROR_TYPE } = require('../../constants/constants'); | ||
|
||
class QueryCommand extends Command { | ||
constructor(ctx) { | ||
super(ctx); | ||
this.queryService = ctx.queryService; | ||
|
||
this.errorType = ERROR_TYPE.QUERY.LOCAL_QUERY_ERROR; | ||
} | ||
|
||
async execute(command) { | ||
const { query, queryType, operationId } = command.data; | ||
|
||
let data; | ||
|
||
await this.operationIdService.updateOperationIdStatus( | ||
operationId, | ||
OPERATION_ID_STATUS.QUERY.QUERY_START, | ||
); | ||
try { | ||
data = await this.queryService.query(query, queryType); | ||
|
||
await this.operationIdService.updateOperationIdStatus( | ||
operationId, | ||
OPERATION_ID_STATUS.QUERY.QUERY_END, | ||
); | ||
|
||
await this.operationIdService.cacheOperationIdData(operationId, data); | ||
|
||
await this.operationIdService.updateOperationIdStatus( | ||
operationId, | ||
OPERATION_ID_STATUS.COMPLETED, | ||
); | ||
} catch (e) { | ||
await this.handleError(operationId, e.message, this.errorType, true); | ||
} | ||
|
||
return Command.empty(); | ||
} | ||
|
||
/** | ||
* Builds default getInitCommand | ||
* @param map | ||
* @returns {{add, data: *, delay: *, deadline: *}} | ||
*/ | ||
default(map) { | ||
const command = { | ||
name: 'queryCommand', | ||
delay: 0, | ||
retries: 0, | ||
transactional: false, | ||
}; | ||
Object.assign(command, map); | ||
return command; | ||
} | ||
} | ||
|
||
module.exports = QueryCommand; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { QUERY_TYPES } = require('../../../constants/constants'); | ||
|
||
module.exports = () => ({ | ||
type: 'object', | ||
required: ['type', 'query'], | ||
properties: { | ||
type: { | ||
enum: [QUERY_TYPES.CONSTRUCT, QUERY_TYPES.SELECT], | ||
}, | ||
query: { | ||
type: 'string', | ||
}, | ||
}, | ||
}); |
Oops, something went wrong.