2023-10-11 01:43:58 +08:00
|
|
|
import Logger from './lib/utils/logger.js';
|
|
|
|
import WorkerStarter from './lib/utils/worker-starter.js';
|
|
|
|
import fs from 'fs';
|
|
|
|
import redis, {commandOptions} from 'redis';
|
|
|
|
import path from 'path';
|
2022-02-10 01:14:52 +08:00
|
|
|
|
|
|
|
const logger = new Logger('presAnn Master');
|
2023-10-11 01:43:58 +08:00
|
|
|
const config = JSON.parse(fs.readFileSync('./config/settings.json', 'utf8'));
|
|
|
|
|
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({
|
|
|
|
password: config.redis.password,
|
2024-02-29 17:36:16 +08:00
|
|
|
socket: {
|
|
|
|
host: config.redis.host,
|
|
|
|
port: config.redis.port
|
|
|
|
}
|
2022-07-27 22:49:25 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
})();
|