Added entry point for main app to batch api
This commit is contained in:
parent
78ee92dbe5
commit
f5ca879ce3
@ -28,6 +28,8 @@ var CacheStatusController = require('./controllers/cache_status_controller');
|
||||
var HealthCheckController = require('./controllers/health_check_controller');
|
||||
var VersionController = require('./controllers/version_controller');
|
||||
|
||||
var batchService = require('../batch');
|
||||
|
||||
process.env.PGAPPNAME = process.env.PGAPPNAME || 'cartodb_sqlapi';
|
||||
|
||||
// override Date.toJSON
|
||||
@ -178,6 +180,8 @@ function App() {
|
||||
var versionController = new VersionController();
|
||||
versionController.route(app);
|
||||
|
||||
batchService(5000, 100);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,11 @@ BatchLauncher.prototype.start = function (interval) {
|
||||
interval = this.batchInterval || interval || 5000;
|
||||
|
||||
this.intervalCallback = setInterval(function () {
|
||||
self.batchManager.run();
|
||||
self.batchManager.run(function (err) {
|
||||
if (err) {
|
||||
console.log('Error in batch service: ', err);
|
||||
}
|
||||
});
|
||||
}, interval);
|
||||
};
|
||||
|
||||
|
@ -16,7 +16,7 @@ BatchManager.prototype.run = function (callback) {
|
||||
}
|
||||
|
||||
if (!username) {
|
||||
return callback(new Error('No jobs scheduled'));
|
||||
return callback(); // no jobs scheduled
|
||||
}
|
||||
|
||||
self.userDatabaseMetadataService.getUserMetadata(username, function (err, userDatabaseMetadata) {
|
||||
@ -31,11 +31,11 @@ BatchManager.prototype.run = function (callback) {
|
||||
|
||||
self.jobService.run(userDatabaseMetadata, function (err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
self.usernameQueue.enqueue(username, function (err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -22,20 +22,23 @@ JobService.prototype.run = function (userDatabaseMetada, callback) {
|
||||
|
||||
self.runJob(pg, job, function (err, jobResult) {
|
||||
if (err) {
|
||||
|
||||
self.setJobFailed(pg, job, err.message, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
callback(null, jobResult);
|
||||
});
|
||||
|
||||
} else {
|
||||
|
||||
self.setJobDone(pg, job, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
console.info('Job %s done successfully', job.job_id);
|
||||
callback(null, jobResult);
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -46,7 +49,7 @@ JobService.prototype.runJob = function (pg, job, callback) {
|
||||
var query = job.query;
|
||||
|
||||
if (job.query.match(/SELECT\s.*FROM\s.*/i)) {
|
||||
query = 'SELECT * INTO job_' + job.job_id.replace(/-/g, '_') + ' FROM (' + job.query + ') as q';
|
||||
query = 'SELECT * INTO "job_' + job.job_id + '" FROM (' + job.query + ') AS j';
|
||||
}
|
||||
|
||||
pg.query(query, function (err, jobResult) {
|
||||
|
Loading…
Reference in New Issue
Block a user