in jobs/index.js [247:288]
this.unsubscribeFromJobs = function(thingName, operationName, callback) {
// Check for omitted optional operationName and fixup parameters
if (isUndefined(callback)) {
callback = operationName;
operationName = null;
}
if ((!isUndefined(options)) && (options.debug === true)) {
console.log('unsubscribeFromJobs:', { thingName: thingName, operationName: operationName });
}
var iThing = jobSubscriptions.findIndex(function(elem) {
return elem.thingName === thingName;
});
var notFoundError = new Error('subscription not found for given thing');
// Check for previously unseen thing and add to job subscriptions and publish to get to retrieve first job to be executed
if (iThing < 0) {
callback(notFoundError);
return;
}
var iOperation = jobSubscriptions[iThing].operations.findIndex(function (elem) {
return (isUndefined(operationName) ? isUndefined(elem.operationName) : operationName === elem.operationName);
});
if (iOperation < 0) {
callback(notFoundError);
return;
}
jobSubscriptions[iThing].operations.splice(iOperation, 1);
if (jobSubscriptions[iThing].operations.length === 0) {
jobSubscriptions.splice(iThing, 1);
device.unsubscribe([ buildJobTopic(thingName, '$next/get/accepted'), buildJobTopic(thingName, 'notify-next') ], callback);
return;
}
callback();
}