CartoDB-SQL-API/batch/index.js
Daniel García Aubert 36d5dc1719 Queue seeker refactor:
- Extract from job subcriber everything related to queue dicovering
 - Job Queue is responsible of queue dicovering and exposes functions to scan user queues.
 - Batch creates an interval to consume queues
 - Now Batch.start() does:
  * Finds existing queues from metadata, adding to queue index the ones that are not indexed yet
  * Binds callback to process jobs for every queue found.
  * Inits queue consumer interval
  * Subscribes to PUB/SUB channel
2017-04-03 19:26:21 +02:00

40 lines
1.5 KiB
JavaScript

'use strict';
var JobRunner = require('./job_runner');
var QueryRunner = require('./query_runner');
var JobCanceller = require('./job_canceller');
var JobSubscriber = require('./pubsub/job-subscriber');
var UserDatabaseMetadataService = require('./user_database_metadata_service');
var JobPublisher = require('./pubsub/job-publisher');
var JobQueue = require('./job_queue');
var JobBackend = require('./job_backend');
var JobService = require('./job_service');
var BatchLogger = require('./batch-logger');
var Batch = require('./batch');
module.exports = function batchFactory (metadataBackend, redisPool, name, statsdClient, loggerPath) {
var userDatabaseMetadataService = new UserDatabaseMetadataService(metadataBackend);
var jobSubscriber = new JobSubscriber(redisPool);
var jobPublisher = new JobPublisher(redisPool);
var jobQueue = new JobQueue(metadataBackend, jobPublisher);
var jobBackend = new JobBackend(metadataBackend, jobQueue);
var queryRunner = new QueryRunner(userDatabaseMetadataService);
var jobCanceller = new JobCanceller(userDatabaseMetadataService);
var jobService = new JobService(jobBackend, jobCanceller);
var jobRunner = new JobRunner(jobService, jobQueue, queryRunner, metadataBackend, statsdClient);
var logger = new BatchLogger(loggerPath);
return new Batch(
name,
userDatabaseMetadataService,
jobSubscriber,
jobQueue,
jobRunner,
jobService,
redisPool,
logger
);
};