// site-worker-process.js // Copyright (C) 2022 DTP Technologies, LLC // License: Apache-2.0 'use strict'; const path = require('path'); const { SiteCommon } = require(path.join(__dirname, 'site-common')); /** * Your actual worker processor will extend SiteWorkerProcess and implement the * expected interface including the. * * Your derived class must implement a static getter for COMPONENT as follows: * * ``` * static get COMPONENT ( ) { return { name: '', slug: '' }; } * ``` * * It must pass that object to this constructor (super) along with the worker * reference you are given at your constructor. * * Your worker logic script can then be a fully-managed process within the DTP * ecosystem. */ class SiteWorkerProcess extends SiteCommon { constructor (worker, component) { super(worker.dtp, component); this.worker = worker; } /** * Utility/convenience method that logs a message to both a Bull Queue job log * and also DTP's logging infrastructure for the worker process. * @param {Job} job Bull queue job for which a log is written * @param {*} message The message to be written * @param {*} data An object containing any data to be logged */ async jobLog (job, message, data = { }) { job.log(message); this.log.info(message, { jobId: job.id, ...data }); } } module.exports.SiteWorkerProcess = SiteWorkerProcess;