Skip to content

Commit 5124735

Browse files
authored
Fix/scheduler action not populated correctly (#25)
* Develop (#8) * added timestamps in the datamodels and notification interval control * removed vsvode env directory from the central repo * Message template changes (#1) * Message template changes * added file ti gitignore * delete package-lock.json * Gitignore .idea * updated a typo * Fix/config (#4) * added readme.md and config to be available from environmental variables * added config doc * Added database docs (#5) * Added database docs * Added link in readme.md * Fix/env var (#6) * added readme.md and config to be available from environmental variables * added config doc * added config to take envvars for sensitive data, fixed directory name typo * fixed a config issue * added healthcheck * Feature/dockerize (#7) * Added Dockerfile * Added Dockerfile and dockerignore * updated readme * error catch * added mongo login information * uri of central ledger in config; healthcheckport -> PORT (#9) * mongodb findAndModify is a mess * typo fix * findandmodifyhell * kafka fix and log * changed /healtcheck to /health * typo fixe * changed package.json info and version * Added initial test to action model and pakage .json to run npm test * completed unit test on tha action model * completed unit test on tha current position model * Add unit tests for events model * Added unit tests for limits model * Added unit tests for notificationEndpoints model * Added unhappy line unit test for database.js * Fixed unhappy line unit test for database.js * Changes to unittest still failing * rewrite unit tests without mocha * rewrite unit tests without mocha mock a db connection * Added ne version of unit test * Fixed the leaked-handles issue * Added database.js unit test for unhappy line * unit test for actions added - incomplete * Added unit test to test if action is finish * added more unit testing to actions * More code for action unit test * added mocking for model.save() * Added unit tests to Actions observable * Added proxyquire to setup unit test * Added code for position change message * added methode for save event * Added code for save event and building params * added more changes to central ledgerAPI and currentpositions model * Added missing js in store * Finished the function to create current position record for settlement change * Finished code changes to centralLedgerApi * cleaned the enums; added action map for kafka and added email-notifier action; added Hub participant name as a config * finished 566 tasks.. time to test * changes for settlement position change implied * few fixes * merged something * ready to merge with master * fixed vulnerabilities * fixed package.json * added notification endpoint call for limits adjustment flow * removed few spaces * fixed opposite logic * fixed naming issue with event collection reference into the action model
1 parent 7ce9840 commit 5124735

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/models/action.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const config = require('../lib/config')
3636
const actionSchema = new mongoose.Schema({
3737
triggeredBy: { type: mongoose.Schema.Types.ObjectId }, // this will show artefact (ndc breach, limit change, etc) in the past
3838
timesTriggered: { type: Number, default: 1 },
39-
fromEvent: { type: mongoose.Schema.Types.ObjectId, ref: 'eventSchema' },
39+
fromEvent: { type: mongoose.Schema.Types.ObjectId, ref: config.mongo.eventCollection },
4040
isActive: { type: Boolean, default: true }
4141
}, { timestamps: true })
4242

src/models/events.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131
const mongoose = require('mongoose')
3232
const config = require('../lib/config')
33-
const getActions = require('../observables/actions').getActions
33+
// const getActions = require('../observables/actions').getActions
3434
/**
3535
* @const limitSchema
3636
*
@@ -39,14 +39,14 @@ const getActions = require('../observables/actions').getActions
3939
* @link https://mongoosejs.com , https://github.com/Automattic/mongoose
4040
*/
4141

42-
let actions = getActions()
42+
// let actions = getActions()
4343

4444
const eventSchema = new mongoose.Schema({
4545
name: { type: String, required: true, index: true },
4646
currency: { type: String, required: true, index: true },
4747
limitType: { type: String, required: true },
4848
notificationEndpointType: { type: String, required: true },
49-
action: { type: String, required: true, enum: actions }, // always sendToKafkaTopic
49+
action: { type: String, required: true, enum: ['produceToKafkaTopic', 'sendEmail'] }, // always sendToKafkaTopic
5050
templateType: { type: String, required: true },
5151
language: { type: String, required: true },
5252
isActive: { type: Boolean, default: true }

src/observables/actions.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const actionObservable = ({ action, params, message }) => {
122122
actionResult = await actionBuilder(action)({ payload }) // create new action
123123
if (Config.get('notificationMinutes').oscilateEvents.includes(params.notificationEndpointType)) {
124124
let actionCreated = await ActionModel.create({ triggeredBy: params.triggeredBy, fromEvent: params.fromEvent })
125-
Rx.asyncScheduler.schedule(clearRepetitionTask, resetPeriod * 60 * 1000, actionCreated.id) // loading the scheduler
125+
Rx.asyncScheduler.schedule(clearRepetitionTask, resetPeriod * 60 * 1000, actionCreated.id) // loading the scheduler, clearRepetitionTask is executed after the period and actionCreated.id is sent as a parameter
126126
} else {
127127
await ActionModel.create({ triggeredBy: params.triggeredBy, fromEvent: params.fromEvent, isActive: false })
128128
}
@@ -137,11 +137,11 @@ const actionObservable = ({ action, params, message }) => {
137137

138138
const clearRepetitionTask = async function (actionId) { // clears the timesTriggered after delay is reached if action is still active
139139
try {
140-
let action = await ActionModel.findById(actionId).populate('eventType')
140+
let action = await ActionModel.findById(actionId).populate('fromEvent')
141141
let limit = await LimitModel.findOne({
142-
type: action.eventType.limitType,
143-
name: action.eventType.name,
144-
currency: action.eventType.currency
142+
type: action.fromEvent.limitType,
143+
name: action.fromEvent.name,
144+
currency: action.fromEvent.currency
145145
})
146146
if (action.isActive && limit) {
147147
action.timesTriggered = 1

0 commit comments

Comments
 (0)