Skip to content

Instantly share code, notes, and snippets.

@aarondai
Created July 16, 2014 17:07
Show Gist options
  • Save aarondai/fef72f7f95d7b63f8bf3 to your computer and use it in GitHub Desktop.
Save aarondai/fef72f7f95d7b63f8bf3 to your computer and use it in GitHub Desktop.
Jut:Collector:Import Function
import : function (data, type, update_position) {
var promise;
var self = this;
if (type === 'records') {
promise = this.importer.add_records(data);
} else if (type === 'points') {
promise = this.importer.add_points(data);
} else {
self.logger.error('Invalid import type');
return Q.reject('Invalid import type');
}
return promise.then(function () {
self.update_status('running');
})
.then(function () {
// update_position is function passed from the subclass that defines
// how the position should be updated so the base class doesn't need
// to know the structure of every collectors position object.
if (update_position) {
update_position();
}
return;
}, function (err) {
if (err.statusCode === 400) {
self.logger.warn(err);
if (update_position) {
update_position();
}
return;
} else {
throw err;
}
})
.then(function () {
return self.save_position();
})
.catch(function (err) {
self.update_status('error', err);
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment