@grouparoo/core
Version:
The Grouparoo Core
42 lines (41 loc) • 1.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnqueueExports = void 0;
const actionhero_1 = require("actionhero");
const Destination_1 = require("../../models/Destination");
const export_1 = require("../../modules/ops/export");
const retryableTask_1 = require("../../classes/tasks/retryableTask");
const plugin_1 = require("../../modules/plugin");
const cls_1 = require("../../modules/cls");
const apiData_1 = require("../../modules/apiData");
class EnqueueExports extends retryableTask_1.RetryableTask {
constructor() {
super(...arguments);
this.name = "export:enqueue";
this.description = "check for pending exports and enqueue other tasks to send them";
this.frequency = 1000 * 10;
this.queue = "exports";
this.inputs = {
count: { required: false, default: 0, formatter: apiData_1.APIData.ensureNumber },
};
}
async runWithinTransaction(params) {
const count = params.count || 0;
const limit = actionhero_1.config.batchSize.exports;
const delayMs = parseInt((await plugin_1.plugin.readSetting("core", "exports-retry-delay-seconds")).value) * 1000;
let totalEnqueued = 0;
const destinations = await Destination_1.Destination.scope(null).findAll();
for (const i in destinations) {
const enqueuedExportsCount = await export_1.ExportOps.processPendingExportsForDestination(destinations[i], limit, delayMs);
totalEnqueued += enqueuedExportsCount;
if (enqueuedExportsCount > 0) {
(0, actionhero_1.log)(`enqueued ${enqueuedExportsCount} exports to send to ${destinations[i].name} (${destinations[i].id})`);
}
}
if (totalEnqueued > 0) {
await cls_1.CLS.enqueueTask(this.name, { count: count + 1 });
}
return totalEnqueued;
}
}
exports.EnqueueExports = EnqueueExports;