-
Notifications
You must be signed in to change notification settings - Fork 1
Timeout implementation #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6413c8a
timer_property
FranckTala b126140
Added delay timer property
FranckTala 00a71be
readme adjustments
FranckTala 1b2f29c
changes in readme file
FranckTala 61926d5
Update README.md
FranckTala 9cb23ce
Bug fixing, turn ON elsint
FranckTala f9bad9f
Merge branch 'timeout_implementation' of https://github.com/elasticio…
FranckTala 5a886b8
fixing bugs
FranckTala 71304fc
fixing bugs
FranckTala 71699b5
fixing bugs
FranckTala 3073f4c
Make Delay required property more consistent.
jhorbulyk f728e0a
fixing bugs
FranckTala 1edbeb0
Revert "fixing bugs"
jhorbulyk e55299f
Stas fomenko patch 1 (#75)
stas-fomenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||
---|---|---|---|---|---|---|
|
@@ -2,7 +2,19 @@ | |||||
const { messages } = require('elasticio-node'); | ||||||
const ObjectStorageWrapperExtended = require('./utils-wrapper/ObjectStorageWrapperExtended'); | ||||||
|
||||||
async function processAction(msg) { | ||||||
let timeHandle; | ||||||
let groupList = []; | ||||||
let groupElements = [{ groupSize: undefined, groupId: undefined, messageData: undefined }]; | ||||||
FranckTala marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
let delay; | ||||||
|
||||||
async function timer(this_) { | ||||||
for (let i = 1; i < groupElements.length; i += 1) { | ||||||
this_.emit('data', messages.newMessageWithBody(groupElements[i])); | ||||||
} | ||||||
FranckTala marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
async function processAction(msg, cfg) { | ||||||
const { mode } = cfg; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
One last change: We should default to having the mode be set to group size in order to ensure backwards compatibility. |
||||||
const storage = new ObjectStorageWrapperExtended(this); | ||||||
const { | ||||||
groupSize, | ||||||
|
@@ -17,13 +29,19 @@ async function processAction(msg) { | |||||
messageData, | ||||||
}; | ||||||
|
||||||
if (groupSize <= 0) { | ||||||
throw new Error('Size must be a positive integer.'); | ||||||
} | ||||||
if (!messageData) { | ||||||
incomingData[messageId] = undefined; | ||||||
} | ||||||
|
||||||
if (mode === 'groupSize') { | ||||||
if (groupSize <= 0) { | ||||||
throw new Error('Size must be a positive integer.'); | ||||||
} | ||||||
} | ||||||
if (mode === 'timeout') { | ||||||
if (msg.body.timersec <= 0) { | ||||||
throw new Error('Delay timer must be a positive integer.'); | ||||||
} | ||||||
} | ||||||
const { | ||||||
messageGroup, | ||||||
messageGroupId, | ||||||
|
@@ -54,19 +72,222 @@ async function processAction(msg) { | |||||
Currently the group has ${messagesNumberSeen} of ${messageGroupSize} message(s).`, | ||||||
); | ||||||
|
||||||
if (messagesNumberSeen >= messageGroupSize) { | ||||||
parsedMessageGroup.messages.forEach((message) => { | ||||||
incomingData[message.messageId] = message.messageData; | ||||||
}); | ||||||
// when group sized is defined || when both group size and delay timer are defined | ||||||
if (mode === 'groupSize') { | ||||||
if (messagesNumberSeen >= messageGroupSize) { | ||||||
parsedMessageGroup.messages.forEach((message) => { | ||||||
incomingData[message.messageId] = message.messageData; | ||||||
}); | ||||||
await this.emit('data', messages.newMessageWithBody({ | ||||||
groupSize, | ||||||
groupId, | ||||||
messageData: incomingData, | ||||||
})); | ||||||
await storage.deleteObjectById(messageGroupId); | ||||||
this.logger.info(`Message group with id ${messageGroupId} has been deleted`); | ||||||
} | ||||||
} | ||||||
|
||||||
// When delay timer option is selected | ||||||
if (mode === 'timeout') { | ||||||
// delay timer | ||||||
delay = msg.body.timersec; | ||||||
delay = (msg.body.timersec >= 40000) ? 40000 : msg.body.timersec; | ||||||
FranckTala marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
clearTimeout(timeHandle); | ||||||
timeHandle = setTimeout(timer, delay, this); | ||||||
|
||||||
await this.emit('data', messages.newMessageWithBody({ | ||||||
groupSize, | ||||||
groupId, | ||||||
messageData: incomingData, | ||||||
})); | ||||||
await storage.deleteObjectById(messageGroupId); | ||||||
this.logger.info(`Message group with id ${messageGroupId} has been deleted`); | ||||||
if (groupList.includes(groupId)) { | ||||||
parsedMessageGroup.messages.forEach((message) => { | ||||||
incomingData[message.messageId] = message.messageData; | ||||||
}); | ||||||
// update incoming messageData in current group | ||||||
const currentGroup = groupElements.filter((x) => x.groupId === groupId); | ||||||
currentGroup[0].groupSize = messagesNumberSeen; | ||||||
currentGroup[0].messageData = incomingData; | ||||||
groupElements = groupElements.filter((x) => x.groupId !== groupId); | ||||||
groupElements.push(currentGroup[0]); | ||||||
} else { | ||||||
parsedMessageGroup.messages.forEach((message) => { | ||||||
incomingData[message.messageId] = message.messageData; | ||||||
}); | ||||||
groupList.push(groupId); | ||||||
groupElements.push({ groupSize: messagesNumberSeen, groupId, messageData: incomingData }); | ||||||
} | ||||||
} | ||||||
|
||||||
// When both groupSize and delay timer option is selected | ||||||
if (mode === 'groupSize&timeout') { | ||||||
delay = msg.body.timersec; | ||||||
delay = (msg.body.timersec >= 40000) ? 40000 : msg.body.timersec; | ||||||
FranckTala marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
clearTimeout(timeHandle); | ||||||
timeHandle = setTimeout(timer, delay, this); | ||||||
|
||||||
if (groupList.includes(groupId)) { | ||||||
parsedMessageGroup.messages.forEach((message) => { | ||||||
incomingData[message.messageId] = message.messageData; | ||||||
}); | ||||||
// update incoming messageData in current group | ||||||
const currentGroup = groupElements.filter((x) => x.groupId === groupId); | ||||||
currentGroup[0].groupSize = messagesNumberSeen; | ||||||
currentGroup[0].messageData = incomingData; | ||||||
groupElements = groupElements.filter((x) => x.groupId !== groupId); | ||||||
groupElements.push(currentGroup[0]); | ||||||
} else { | ||||||
parsedMessageGroup.messages.forEach((message) => { | ||||||
incomingData[message.messageId] = message.messageData; | ||||||
}); | ||||||
groupList.push(groupId); | ||||||
groupElements.push({ groupSize: messagesNumberSeen, groupId, messageData: incomingData }); | ||||||
} | ||||||
if (messagesNumberSeen >= messageGroupSize) { | ||||||
parsedMessageGroup.messages.forEach((message) => { | ||||||
incomingData[message.messageId] = message.messageData; | ||||||
}); | ||||||
|
||||||
await this.emit('data', messages.newMessageWithBody({ | ||||||
groupSize, | ||||||
groupId, | ||||||
messageData: incomingData, | ||||||
})); | ||||||
await storage.deleteObjectById(messageGroupId); | ||||||
this.logger.info(`Message group with id ${messageGroupId} has been deleted`); | ||||||
groupList = groupList.filter((def) => def !== groupId); | ||||||
groupElements = groupElements.filter((def) => def.groupId !== groupId); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
exports.process = processAction; | ||||||
//------------------------------------------------------------------------------------- | ||||||
// Dynamic drop-down logic starts hier | ||||||
|
||||||
async function getMetaModel(cfg) { | ||||||
if (cfg.mode === 'groupSize') { | ||||||
return ({ | ||||||
in: { | ||||||
type: 'object', | ||||||
required: true, | ||||||
properties: { | ||||||
groupId: { | ||||||
type: 'string', | ||||||
required: true, | ||||||
title: 'Unique ID to describe the group', | ||||||
order: 5, | ||||||
}, | ||||||
messageId: { | ||||||
type: 'string', | ||||||
required: true, | ||||||
title: 'Unique ID to describe this message', | ||||||
order: 4, | ||||||
}, | ||||||
groupSize: { | ||||||
type: 'number', | ||||||
required: true, | ||||||
title: 'Number of messages produced by splitter', | ||||||
order: 3, | ||||||
}, | ||||||
messageData: { | ||||||
title: 'Message Data', | ||||||
required: false, | ||||||
type: 'object', | ||||||
properties: {}, | ||||||
order: 2, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
out: { | ||||||
type: 'object', | ||||||
}, | ||||||
}); | ||||||
} | ||||||
if (cfg.mode === 'timeout') { | ||||||
return ({ | ||||||
in: { | ||||||
type: 'object', | ||||||
required: true, | ||||||
properties: { | ||||||
groupId: { | ||||||
type: 'string', | ||||||
required: true, | ||||||
title: 'Unique ID to describe the group', | ||||||
order: 5, | ||||||
}, | ||||||
messageId: { | ||||||
type: 'string', | ||||||
required: true, | ||||||
title: 'Unique ID to describe this message', | ||||||
order: 4, | ||||||
}, | ||||||
timersec: { | ||||||
type: 'number', | ||||||
required: true, | ||||||
help: { | ||||||
description: 'Time the process waits when no incoming messages before emiting(Default 20000 miliseconds)', | ||||||
}, | ||||||
title: 'Delay timer(in ms)', | ||||||
order: 3, | ||||||
}, | ||||||
messageData: { | ||||||
title: 'Message Data', | ||||||
required: false, | ||||||
type: 'object', | ||||||
properties: {}, | ||||||
order: 2, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
out: { | ||||||
type: 'object', | ||||||
}, | ||||||
}); | ||||||
} | ||||||
if (cfg.mode === 'groupSize&timeout') { | ||||||
return ({ | ||||||
in: { | ||||||
type: 'object', | ||||||
required: true, | ||||||
properties: { | ||||||
groupId: { | ||||||
type: 'string', | ||||||
required: true, | ||||||
title: 'Unique ID to describe the group', | ||||||
order: 5, | ||||||
}, | ||||||
messageId: { | ||||||
type: 'string', | ||||||
required: true, | ||||||
title: 'Unique ID to describe this message', | ||||||
order: 4, | ||||||
}, | ||||||
groupSize: { | ||||||
type: 'number', | ||||||
title: 'Number of messages produced by splitter', | ||||||
order: 3, | ||||||
}, | ||||||
timersec: { | ||||||
type: 'number', | ||||||
help: { | ||||||
description: 'Time the process waits when no incoming messages before emiting(Default 20000 miliseconds)', | ||||||
}, | ||||||
title: 'Delay timer(in ms)', | ||||||
order: 2, | ||||||
}, | ||||||
messageData: { | ||||||
title: 'Message Data', | ||||||
required: false, | ||||||
type: 'object', | ||||||
properties: {}, | ||||||
order: 1, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
out: { | ||||||
type: 'object', | ||||||
}, | ||||||
}); | ||||||
} | ||||||
return true; | ||||||
FranckTala marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
module.exports = { | ||||||
process: processAction, | ||||||
getMetaModel, | ||||||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.