2022-02-10 01:14:52 +08:00
|
|
|
const Logger = require('./lib/utils/logger');
|
2022-11-12 00:51:30 +08:00
|
|
|
const WorkerStarter = require('./lib/utils/worker-starter');
|
2022-02-10 01:14:52 +08:00
|
|
|
const config = require('./config');
|
|
|
|
const fs = require('fs');
|
|
|
|
const redis = require('redis');
|
2022-07-27 22:49:25 +08:00
|
|
|
const {commandOptions} = require('redis');
|
2022-04-29 19:50:42 +08:00
|
|
|
const path = require('path');
|
2022-02-10 01:14:52 +08:00
|
|
|
|
|
|
|
const logger = new Logger('presAnn Master');
|
2022-07-27 22:49:25 +08:00
|
|
|
logger.info('Running bbb-export-annotations');
|
2022-02-10 01:14:52 +08:00
|
|
|
|
|
|
|
(async () => {
|
2022-07-27 22:49:25 +08:00
|
|
|
const client = redis.createClient({
|
|
|
|
host: config.redis.host,
|
|
|
|
port: config.redis.port,
|
|
|
|
password: config.redis.password,
|
|
|
|
});
|
|
|
|
|
|
|
|
await client.connect();
|
|
|
|
|
|
|
|
client.on('error', (err) => logger.info('Redis Client Error', err));
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pops new export requests from a Redis queue, blocking the
|
|
|
|
* connection otherwise.
|
|
|
|
*/
|
|
|
|
async function waitForJobs() {
|
|
|
|
const queue = client.blPop(
|
|
|
|
commandOptions({isolated: true}),
|
|
|
|
config.redis.channels.queue,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
|
|
|
|
const job = await queue;
|
|
|
|
|
|
|
|
logger.info('Received job', job.element);
|
|
|
|
const exportJob = JSON.parse(job.element);
|
2022-11-12 00:51:30 +08:00
|
|
|
const jobId = exportJob.jobId;
|
2022-07-27 22:49:25 +08:00
|
|
|
|
|
|
|
// Create folder in dropbox
|
2022-11-12 00:51:30 +08:00
|
|
|
const dropbox = path.join(config.shared.presAnnDropboxDir, jobId);
|
2022-07-27 22:49:25 +08:00
|
|
|
fs.mkdirSync(dropbox, {recursive: true});
|
|
|
|
|
|
|
|
// Drop job into dropbox as JSON
|
|
|
|
fs.writeFile(path.join(dropbox, 'job'), job.element, function(err) {
|
|
|
|
if (err) {
|
|
|
|
return logger.error(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-11-12 00:51:30 +08:00
|
|
|
const collectorWorker = new WorkerStarter({jobId});
|
|
|
|
collectorWorker.collect();
|
2022-04-27 19:12:16 +08:00
|
|
|
waitForJobs();
|
2022-07-27 22:49:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
waitForJobs();
|
2022-02-10 01:14:52 +08:00
|
|
|
})();
|