Work in progress on integration of IVIS.

Some fixes.
This commit is contained in:
Tomas Bures 2019-08-31 11:46:18 +02:00
parent 3a17d7fd75
commit 2aaa8f45b3
11 changed files with 188 additions and 12 deletions

View file

@ -1,7 +1,37 @@
'use strict';
const moment = require('moment');
const activityQueueLenthThreshold = 100;
const actitivyQueue = [];
let processQueueIsRunning = false;
async function processQueue() {
if (processQueueIsRunning) {
return;
}
processQueueIsRunning = true;
// XXX submit data to IVIS if configured in config
actitivyQueue.splice(0);
processQueueIsRunning = false;
}
async function _logActivity(typeId, data) {
// TODO
actitivyQueue.push({
typeId,
data,
timestamp: moment.utc().toISOString()
});
if (actitivyQueue.length >= activityQueueLenthThreshold) {
// noinspection ES6MissingAwait
processQueue();
}
}
/*

View file

@ -4,8 +4,12 @@ const config = require('../lib/config');
const log = require('../lib/log');
const mailers = require('../lib/mailers');
const messageSender = require('../lib/message-sender');
const {CampaignTrackerActivityType} = require('../../shared/activity-log');
const activityLog = require('../lib/activity-log');
require('../lib/fork');
const MessageType = messageSender.MessageType;
const workerId = Number.parseInt(process.argv[2]);
let running = false;
@ -26,6 +30,8 @@ async function processCampaignMessages(campaignId, messages) {
try {
await cs.sendRegularCampaignMessage(campaignMessage);
await activityLog.logCampaignTrackerActivity(CampaignTrackerActivityType.SENT, campaignId, campaignMessage.list, campaignMessage.subscription);
log.verbose('Senders', 'Message sent and status updated for %s:%s', campaignMessage.list, campaignMessage.subscription);
} catch (err) {
@ -58,6 +64,8 @@ async function processQueuedMessages(sendConfigurationId, messages) {
for (const queuedMessage of messages) {
const messageType = queuedMessage.type;
const msgData = queuedMessage.data;
let target = '';
if (msgData.listId && msgData.subscriptionId) {
@ -74,6 +82,11 @@ async function processQueuedMessages(sendConfigurationId, messages) {
try {
await messageSender.sendQueuedMessage(queuedMessage);
if ((messageType === MessageType.TRIGGERED || messageType === MessageType.TEST) && msgData.campaignId && msgData.listId && msgData.subscriptionId) {
await activityLog.logCampaignTrackerActivity(CampaignTrackerActivityType.SENT, msgData.campaignId, msgData.listId, msgData.subscriptionId);
}
log.verbose('Senders', `Message sent and status updated for ${target}`);
} catch (err) {
if (err instanceof mailers.SendConfigurationError) {