-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added maester-library to re-assembling messages action (#70)
Implemented support of maester storage in `Re-assembled message` action (maester-client library 3.3.0)
- Loading branch information
Showing
7 changed files
with
687 additions
and
60 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
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,58 @@ | ||
const { ObjectStorageWrapper } = require('@elastic.io/maester-client/dist/ObjectStorageWrapper'); | ||
|
||
class ObjectStorageWrapperExtended extends ObjectStorageWrapper { | ||
constructor(context) { | ||
super(context); | ||
this.logger = context.logger; | ||
this.EXTERNAL_ID_QUERY_HEADER_NAME = 'externalid'; | ||
this.TTL_TWO_DAYS = 172800; | ||
} | ||
|
||
async lookupParsedObjectById(messageGroupId) { | ||
const messageGroup = await this.lookupObjectById(messageGroupId); | ||
return JSON.parse(messageGroup); | ||
} | ||
|
||
async createMessageGroupIfNotExists(externalId, messageGroupSize) { | ||
this.logger.info('Processing creation of the new message group'); | ||
const messageGroups = await this.lookupObjectsByQueryParameters( | ||
[{ key: this.EXTERNAL_ID_QUERY_HEADER_NAME, value: externalId }], | ||
); | ||
if (messageGroups.length > 1) { | ||
throw new Error('Several message groups with the same ids can not exist'); | ||
} | ||
if (!messageGroups.length) { | ||
this.logger.info('No message groups found'); | ||
const newMessageGroup = { | ||
messages: [], | ||
messageIdsSeen: {}, | ||
}; | ||
const { objectId: messageGroupId } = await this.createObject( | ||
newMessageGroup, [{ key: this.EXTERNAL_ID_QUERY_HEADER_NAME, value: externalId }], | ||
[], this.TTL_TWO_DAYS, | ||
); | ||
this.logger.info('Created new message group'); | ||
return { | ||
messageGroup: newMessageGroup, messageGroupSize, messageGroupId, isCreated: true, | ||
}; | ||
} | ||
this.logger.info('MessageGroup found'); | ||
const messageGroupId = messageGroups[0].objectId; | ||
const parsedMessageGroup = await this.lookupParsedObjectById(messageGroupId); | ||
return { | ||
messageGroup: parsedMessageGroup, messageGroupSize, messageGroupId, isCreated: false, | ||
}; | ||
} | ||
|
||
async createNewObjectInMessageGroup(object, messageGroupId) { | ||
this.logger.info('Processing creation of the new object'); | ||
const parsedMessageGroup = await this.lookupParsedObjectById(messageGroupId); | ||
this.logger.info('...Updating message group'); | ||
parsedMessageGroup.messageIdsSeen[object.messageId] = object.messageId; | ||
return this.updateObject(messageGroupId, { | ||
...parsedMessageGroup, messages: [...parsedMessageGroup.messages, object], | ||
}); | ||
} | ||
} | ||
|
||
module.exports = ObjectStorageWrapperExtended; |
Oops, something went wrong.