2018-09-02 12:59:02 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const log = require('npmlog');
|
|
|
|
const mailers = require('../lib/mailers');
|
|
|
|
|
|
|
|
const workerId = Number.parseInt(process.argv[2]);
|
|
|
|
let running = false;
|
|
|
|
|
|
|
|
/*
|
|
|
|
const knex = require('../lib/knex');
|
|
|
|
const path = require('path');
|
|
|
|
const log = require('npmlog');
|
|
|
|
const fsExtra = require('fs-extra-promise');
|
|
|
|
const {ImportSource, MappingType, ImportStatus, RunStatus} = require('../shared/imports');
|
|
|
|
const imports = require('../models/imports');
|
|
|
|
const fields = require('../models/fields');
|
|
|
|
const subscriptions = require('../models/subscriptions');
|
|
|
|
const { Writable } = require('stream');
|
|
|
|
const { cleanupFromPost, enforce } = require('../lib/helpers');
|
|
|
|
const contextHelpers = require('../lib/context-helpers');
|
|
|
|
const tools = require('../lib/tools');
|
|
|
|
const shares = require('../models/shares');
|
|
|
|
const _ = require('../lib/translate')._;
|
|
|
|
*/
|
|
|
|
|
2018-09-09 22:55:44 +00:00
|
|
|
async function processMessages(msgs) {
|
2018-09-02 12:59:02 +00:00
|
|
|
if (running) {
|
|
|
|
log.error('Senders', `Worker ${workerId} assigned work while working`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
running = true;
|
|
|
|
|
2018-09-09 22:55:44 +00:00
|
|
|
console.log(msgs);
|
2018-09-02 12:59:02 +00:00
|
|
|
// FIXME
|
|
|
|
|
|
|
|
running = false;
|
2018-09-09 22:55:44 +00:00
|
|
|
|
|
|
|
sendToMaster('messages-processed');
|
2018-09-02 12:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function sendToMaster(msgType) {
|
|
|
|
process.send({
|
|
|
|
type: msgType
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on('message', msg => {
|
|
|
|
if (msg) {
|
|
|
|
const type = msg.type;
|
|
|
|
|
2018-09-09 22:55:44 +00:00
|
|
|
if (type === 'reload-config') {
|
2018-09-02 12:59:02 +00:00
|
|
|
mailers.invalidateMailer(msg.data.sendConfigurationId);
|
|
|
|
|
2018-09-09 22:55:44 +00:00
|
|
|
} else if (type === 'process-messages') {
|
|
|
|
// noinspection JSIgnoredPromiseFromCall
|
|
|
|
processMessages(msg.data)
|
2018-09-02 12:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
sendToMaster('worker-started');
|
|
|
|
|
|
|
|
|