Skip to content

Commit

Permalink
Await reconnect before job flush (#28)
Browse files Browse the repository at this point in the history
* wait for a keepalive from the server before re-running jobs on disconnect

* 4.0.19

* jshint fix

* Handle NULL_TYPE and INT_TYPE when parsing binary data batches

* 4.0.20
  • Loading branch information
kchengsf authored and 9park committed Feb 4, 2017
1 parent 328b1cb commit b15f0b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/client/signalflow/request_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var SSE = require('sse.js');


function RequestManager(endPoint) {
var awaitingKeepaliveConfirmation = false;
var knownComputations = {};
var requestIdIndex = 0;
var maxJobCount = 10000;
Expand Down Expand Up @@ -53,6 +54,12 @@ function RequestManager(endPoint) {
var parsedMsg = sfxWSMsgHandler.parseWebSocketMessage(msg, knownComputations);
if (parsedMsg.event === 'KEEP_ALIVE') {
lastKeepAliveTime = Date.now();
if (awaitingKeepaliveConfirmation) {
Object.keys(knownComputations).forEach(function (computation) {
knownComputations[computation].streamController.retry();
});
awaitingKeepaliveConfirmation = false;
}
}

if (parsedMsg.event === 'JOB_START') {
Expand Down Expand Up @@ -118,9 +125,7 @@ function RequestManager(endPoint) {
function reconnect(token) {
wsConnectionOpen = false;
authenticate(token);
Object.keys(knownComputations).forEach(function (computation) {
knownComputations[computation].streamController.retry();
});
awaitingKeepaliveConfirmation = true;
}

function authenticate(token) {
Expand All @@ -146,7 +151,6 @@ function RequestManager(endPoint) {
activeSocket.close();
}


activeSocket = new WebSocket(wsEndpoint + '/v2/signalflow/connect');
activeSocket.binaryType = 'arraybuffer';
activeSocket.onmessage = onWebSocketMessage;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "signalfx",
"version": "4.0.19",
"version": "4.0.20",
"description": "Node.js client library for SignalFx",
"homepage": "https://signalfx.com",
"repository": "https://github.com/signalfx/signalfx-nodejs",
Expand Down

0 comments on commit b15f0b2

Please sign in to comment.