-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from matthew-larner/SP-3-LiveReviewPooling
Sp-3 Live Review Pooling
- Loading branch information
Showing
8 changed files
with
225 additions
and
420 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ services: | |
networks: | ||
- app | ||
networks: | ||
app: | ||
app: |
Large diffs are not rendered by default.
Oops, something went wrong.
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,64 @@ | ||
import { MonitorReviewUpdatesPayloadInterface, ReviewDataInterface, LiveReviewRequestType } from '../contracts'; | ||
import * as inception from './inception'; | ||
import * as mqtt from './mqtt'; | ||
|
||
export const polling = async () => { | ||
|
||
const liveReviewEvents = 'LiveReviewEvents'; | ||
|
||
const publishLiveReviewUpdates = (data: ReviewDataInterface) => { | ||
const topic = `inception/event`; | ||
const { Description, MessageCategory, What, Where } = data; | ||
|
||
mqtt.publish(topic, JSON.stringify({ | ||
Description, | ||
MessageCategory, | ||
What, | ||
Where | ||
})); | ||
}; | ||
|
||
let monitorUpdatesPayload: MonitorReviewUpdatesPayloadInterface[]; | ||
const initPayload = () => { | ||
monitorUpdatesPayload = [ | ||
{ | ||
ID: liveReviewEvents, | ||
RequestType: liveReviewEvents, | ||
InputData: { | ||
referenceId: null, | ||
referenceTime: null | ||
} | ||
} | ||
]; | ||
} | ||
|
||
while (true) { | ||
try { | ||
if (!monitorUpdatesPayload) { | ||
initPayload(); | ||
} | ||
|
||
console.log('Polling monitor updates with payload ' + JSON.stringify(monitorUpdatesPayload)); | ||
|
||
const response = await inception.monitorUpdates(monitorUpdatesPayload, initPayload); | ||
const results = response.Result as unknown as ReviewDataInterface[]; | ||
const newMonitorUpdatesPayload = []; | ||
|
||
for( let result of results) { | ||
publishLiveReviewUpdates(result); | ||
newMonitorUpdatesPayload.push({ | ||
ID: liveReviewEvents, | ||
RequestType: liveReviewEvents, | ||
InputData: { | ||
referenceId: result.ID, | ||
referenceTime: result.WhenTicks | ||
} | ||
}); | ||
monitorUpdatesPayload = newMonitorUpdatesPayload; | ||
} | ||
|
||
} catch (error) { | ||
console.error('Inception polling encountered an error: ', error.message); | ||
} | ||
} | ||
}; |
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