2016-07-20 01:42:49 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-07-20 01:56:12 +08:00
|
|
|
require('../../helper');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-07-20 01:56:12 +08:00
|
|
|
var BATCH_SOURCE = '../../../batch/';
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-07-20 01:56:12 +08:00
|
|
|
var assert = require('../../support/assert');
|
2016-07-22 23:05:01 +08:00
|
|
|
var redisUtils = require('../../support/redis_utils');
|
2016-07-20 01:42:49 +08:00
|
|
|
|
|
|
|
var JobQueue = require(BATCH_SOURCE + 'job_queue');
|
|
|
|
var JobBackend = require(BATCH_SOURCE + 'job_backend');
|
2016-10-12 00:28:46 +08:00
|
|
|
var JobPublisher = require(BATCH_SOURCE + 'pubsub/job-publisher');
|
2016-07-20 01:42:49 +08:00
|
|
|
var jobStatus = require(BATCH_SOURCE + 'job_status');
|
|
|
|
var UserDatabaseMetadataService = require(BATCH_SOURCE + 'user_database_metadata_service');
|
|
|
|
var JobCanceller = require(BATCH_SOURCE + 'job_canceller');
|
|
|
|
var JobService = require(BATCH_SOURCE + 'job_service');
|
|
|
|
var JobRunner = require(BATCH_SOURCE + 'job_runner');
|
|
|
|
var QueryRunner = require(BATCH_SOURCE + 'query_runner');
|
|
|
|
|
|
|
|
|
2016-10-17 21:02:34 +08:00
|
|
|
var metadataBackend = require('cartodb-redis')({ pool: redisUtils.getPool() });
|
|
|
|
var jobPublisher = new JobPublisher(redisUtils.getPool());
|
2016-07-20 01:42:49 +08:00
|
|
|
var jobQueue = new JobQueue(metadataBackend, jobPublisher);
|
2016-08-31 01:06:59 +08:00
|
|
|
var jobBackend = new JobBackend(metadataBackend, jobQueue);
|
2016-07-20 01:42:49 +08:00
|
|
|
var userDatabaseMetadataService = new UserDatabaseMetadataService(metadataBackend);
|
2018-05-30 23:36:55 +08:00
|
|
|
var jobCanceller = new JobCanceller();
|
2016-07-20 01:42:49 +08:00
|
|
|
var jobService = new JobService(jobBackend, jobCanceller);
|
|
|
|
var queryRunner = new QueryRunner(userDatabaseMetadataService);
|
|
|
|
var StatsD = require('node-statsd').StatsD;
|
|
|
|
var statsdClient = new StatsD(global.settings.statsd);
|
|
|
|
|
|
|
|
var USER = 'vizzuality';
|
|
|
|
var QUERY = 'select pg_sleep(0)';
|
|
|
|
var HOST = 'localhost';
|
|
|
|
var JOB = {
|
|
|
|
user: USER,
|
|
|
|
query: QUERY,
|
2018-05-28 23:38:04 +08:00
|
|
|
host: HOST,
|
|
|
|
dbname: 'cartodb_test_user_1_db',
|
|
|
|
dbuser: 'test_cartodb_user_1',
|
|
|
|
port: 5432,
|
|
|
|
pass: 'test_cartodb_user_1_pass',
|
2016-07-20 01:42:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
describe('job runner', function() {
|
2016-10-21 20:35:24 +08:00
|
|
|
var jobRunner = new JobRunner(jobService, jobQueue, queryRunner, metadataBackend, statsdClient);
|
2016-07-20 01:42:49 +08:00
|
|
|
|
2016-07-22 20:27:18 +08:00
|
|
|
after(function (done) {
|
2016-10-21 20:35:24 +08:00
|
|
|
redisUtils.clean('batch:*', function() {
|
|
|
|
redisUtils.clean('limits:batch:*', done);
|
|
|
|
});
|
2016-07-22 20:27:18 +08:00
|
|
|
});
|
|
|
|
|
2016-07-20 01:42:49 +08:00
|
|
|
it('.run() should run a job', function (done) {
|
|
|
|
jobService.create(JOB, function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobRunner.run(job.data.job_id, function (err, job) {
|
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.equal(job.data.status, jobStatus.DONE);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('.run() should return a job not found error', function (done) {
|
|
|
|
jobRunner.run('wadus_job_id', function (err) {
|
|
|
|
assert.ok(err, err);
|
|
|
|
assert.equal(err.name, 'NotFoundError');
|
|
|
|
assert.equal(err.message, 'Job with id wadus_job_id not found');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|