"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkerService = exports.WorkerJob = exports.BaseJob = void 0;
const tslib_1 = require("tslib");
/*@ts-ignore*/
var { __ΩClassType } = require('@deepkit/core');
const const_1 = require("../../app/const");
const logger_1 = require("../logger");
const queue_1 = require("./queue");
/*@ts-ignore*/
var { __ΩIJobOptions } = require('./types');
const types_1 = require("./types");
tslib_1.__exportStar(require("./entity"), exports);
var types_2 = require("./types");
Object.defineProperty(exports, "BaseJob", { enumerable: true, get: function () { return types_2.BaseJob; } });
Object.defineProperty(exports, "WorkerJob", { enumerable: true, get: function () { return types_2.WorkerJob; } });
class WorkerService {
    constructor() {
        this.logger = (0, logger_1.createLogger)(this);
    }
    async queueJob(jobClass, data, options) {
        if (const_1.isTest) {
            this.logger.warn('Not queueing job in test environment', { jobName: jobClass.name, data, options });
            return;
        }
        try {
            const typedJob = jobClass;
            const queue = queue_1.WorkerQueueRegistry.getQueue(typedJob.QUEUE_NAME);
            const job = await queue.add(jobClass.name, data, options);
            this.logger.info('Queued job', { job: { name: jobClass.name, id: job.id } });
        }
        catch (err) {
            this.logger.error('Failed to queue job', err, { job: { name: jobClass.name } });
            throw err;
        }
    }
}
exports.WorkerService = WorkerService;
WorkerService.__type = ['logger', function () { return (0, logger_1.createLogger)(this); }, () => __ΩClassType, 'jobClass', () => types_1.InputDataSymbol, 'data', () => __ΩIJobOptions, 'options', 'queueJob', 'WorkerService', '!3!;>"P"o#"2$"i%f2&n\'2(8"0)5w*'];
//# sourceMappingURL=index.js.map