Skip to content

Commit

Permalink
Merge pull request #206 from kaltura/test
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
gadyaari authored Jun 26, 2016
2 parents 5656521 + 5877c3d commit 11a1587
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions lib/entry/LiveEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,43 @@ function updateStreamInfo(flavorsObjArray) {
});
}

function checkForErrors(results) {
var that = this;
var errs = ErrorUtils.aggregateErrors(results);
if (errs.numErrors === results.length) {
// Fail if no flavor downloader could be started
throw new Error("Failed to start entry downloader for entry: %s. All flavor downloaders failed", that.entryId);
}
if (errs.numErrors > 0) {
// Report an error (but proceed) if only some flavor downloaders could not be started
that.logger.error("Failed to start flavor downloaders for some of the flavors: %s ", ErrorUtils.error2string(errs.err));
}
}

function getEntryServerNodeId() {
var that = this;
var getLiveEntryServerNodeIdPromise =
that.entryServerNodeId ? Q.Promise.resolve(that.entryServerNodeId)
: backendClient.getLiveEntryServerNodes(that.entryId).then(function(liveEntryServerNodes) {

that.entryServerNodeId = 0;
_.each(liveEntryServerNodes, function(liveEntryServerNode) {
if (liveEntryServerNode.serverType === that.entryServerType) {
that.entryServerNodeId = liveEntryServerNode.id;
return false;
}
});

}).catch(function() {
that.entryServerNodeId = 0;
return null;
});

getLiveEntryServerNodeIdPromise.then(function() {
updateStreamInfo.call(that);
});
}

LiveEntry.prototype.start = function() {
var that = this;
// Entry created -> report BROADCASTING to server
Expand All @@ -102,32 +139,15 @@ LiveEntry.prototype.start = function() {
return that.playlistGenerator.createManifest();
})
.then(function(flavorsObjArray) {

var getLiveEntryServerNodeIdPromise =
that.entryServerNodeId ? Q.Promise.resolve(that.entryServerNodeId)
: backendClient.getLiveEntryServerNodeId(that.entryId, that.entryServerType);

getLiveEntryServerNodeIdPromise.then(function(entryServerNodeId) {
that.entryServerNodeId = entryServerNodeId;
updateStreamInfo.call(that, flavorsObjArray);
});

getEntryServerNodeId.call(that);
return flavorsObjArray;
})
.then(function(result) {
// Create a flavorDownloader for each of the flavors currently streaming
return createFlavorDownloaders.call(that, result);
})
.then(function(results) {
var errs = ErrorUtils.aggregateErrors(results);
if (errs.numErrors === results.length) {
// Fail if no flavor downloader could be started
throw new Error("Failed to start entry downloader for entry: %s. All flavor downloaders failed", that.entryId);
}
if (errs.numErrors > 0) {
// Report an error (but proceed) if only some flavor downloaders could not be started
that.logger.error("Failed to start flavor downloaders for some of the flavors: %s ", ErrorUtils.error2string(errs.err));
}
checkForErrors.call(that, results);
});
};

Expand All @@ -150,7 +170,7 @@ LiveEntry.prototype.stop = function() {
// Regardless of the stopping result worker must remove entry from handledEntries list
return Q.all(flavorsPromises)
.then(function() {
var stopPromise = that.FSM.stop()
var stopPromise = that.FSM.stop();
return stopPromise
.catch(function(err) {
that.logger.error("Error calling FSM.stop: %s" ,ErrorUtils.error2string(err));
Expand Down

0 comments on commit 11a1587

Please sign in to comment.