2016-01-08 18:32:01 +08:00
|
|
|
'use strict';
|
|
|
|
|
2016-07-07 20:14:46 +08:00
|
|
|
var RedisPool = require('redis-mpool');
|
|
|
|
var _ = require('underscore');
|
2016-01-08 18:32:01 +08:00
|
|
|
var JobRunner = require('./job_runner');
|
2016-03-31 18:39:03 +08:00
|
|
|
var QueryRunner = require('./query_runner');
|
2016-01-13 23:25:25 +08:00
|
|
|
var JobCanceller = require('./job_canceller');
|
2016-01-08 18:32:01 +08:00
|
|
|
var JobQueuePool = require('./job_queue_pool');
|
|
|
|
var JobSubscriber = require('./job_subscriber');
|
2016-04-04 22:05:33 +08:00
|
|
|
var QueueSeeker = require('./queue_seeker');
|
2016-01-08 18:32:01 +08:00
|
|
|
var UserDatabaseMetadataService = require('./user_database_metadata_service');
|
|
|
|
var JobPublisher = require('./job_publisher');
|
|
|
|
var JobQueue = require('./job_queue');
|
2016-01-08 22:47:59 +08:00
|
|
|
var JobBackend = require('./job_backend');
|
2016-05-14 00:50:55 +08:00
|
|
|
var JobService = require('./job_service');
|
2016-09-29 21:09:36 +08:00
|
|
|
var BatchLogger = require('./batch-logger');
|
2016-01-08 18:32:01 +08:00
|
|
|
var Batch = require('./batch');
|
|
|
|
|
2016-09-29 21:09:36 +08:00
|
|
|
module.exports = function batchFactory (metadataBackend, redisConfig, statsdClient, loggerPath) {
|
2016-07-07 20:14:46 +08:00
|
|
|
var redisPoolSubscriber = new RedisPool(_.extend(redisConfig, { name: 'batch-subscriber'}));
|
|
|
|
var redisPoolPublisher = new RedisPool(_.extend(redisConfig, { name: 'batch-publisher'}));
|
2016-04-04 22:05:33 +08:00
|
|
|
var queueSeeker = new QueueSeeker(metadataBackend);
|
2016-07-07 20:14:46 +08:00
|
|
|
var jobSubscriber = new JobSubscriber(redisPoolSubscriber, queueSeeker);
|
|
|
|
var jobPublisher = new JobPublisher(redisPoolPublisher);
|
2016-06-30 00:29:53 +08:00
|
|
|
var jobQueuePool = new JobQueuePool(metadataBackend, jobPublisher);
|
|
|
|
var jobQueue = new JobQueue(metadataBackend, jobPublisher);
|
2016-08-31 01:01:23 +08:00
|
|
|
var jobBackend = new JobBackend(metadataBackend, jobQueue);
|
2016-01-08 22:47:59 +08:00
|
|
|
var userDatabaseMetadataService = new UserDatabaseMetadataService(metadataBackend);
|
2016-05-23 23:51:56 +08:00
|
|
|
var queryRunner = new QueryRunner(userDatabaseMetadataService);
|
2016-05-16 07:22:47 +08:00
|
|
|
var jobCanceller = new JobCanceller(userDatabaseMetadataService);
|
2016-05-14 00:50:55 +08:00
|
|
|
var jobService = new JobService(jobBackend, jobCanceller);
|
2016-06-03 18:03:17 +08:00
|
|
|
var jobRunner = new JobRunner(jobService, jobQueue, queryRunner, statsdClient);
|
2016-09-29 21:09:36 +08:00
|
|
|
var logger = new BatchLogger(loggerPath);
|
2016-01-08 18:32:01 +08:00
|
|
|
|
2016-09-29 21:09:36 +08:00
|
|
|
return new Batch(jobSubscriber, jobQueuePool, jobRunner, jobService, logger);
|
2016-01-08 18:32:01 +08:00
|
|
|
};
|