Skip to content

Commit

Permalink
extend events create API (#71)
Browse files Browse the repository at this point in the history
add duration and spare setters
  • Loading branch information
Jussi Vatjus-Anttila authored Dec 12, 2018
1 parent e05eb41 commit 25e00ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class Event extends Document {
if (value) invariant(Event.FACILITIES.indexOf(value) >= 0, 'Not allowed facility');
return this.getOrSet('priority.facility', value);
}
duration(value) {
if (value) invariant(_.isNumber(value), 'value should be an number');
return this.getOrSet('duration', value);
}
spare(value) {
return this.getOrSet('spare', value);
}
id(value) {
// e.g. PID of the process
return this.getOrSet('id', value);
Expand Down
4 changes: 4 additions & 0 deletions test/api/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ describe('Event', function () {
.info()
.debug()
.alert()
.duration(2)
.spare(1)
.facility('resource')
.id('abc')
.allocated()
Expand All @@ -94,6 +96,8 @@ describe('Event', function () {
_id: '123',
tag: 'test',
id: 'abc',
duration: 2,
spare: 1,
msg: 'hohhoi',
priority: {level: 'alert', facility: 'resource'},
msgid: 'ALLOCATED'
Expand Down

0 comments on commit 25e00ab

Please sign in to comment.