{"version":3,"sources":["../src/entities/job.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD;IAKgB,SAAS,CAAC,aAAa,EAAE,aAAa;IAJ3C,OAAO,EAAE,OAAO,CAAS;IACzB,MAAM,EAAE,OAAO,CAAS;IAC/B,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC;gBAER,aAAa,EAAE,aAAa;aA2BlC,QAAQ,IAAI,MAAM;aACZ,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAEhD,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAWpD","file":"job.d.ts","sourcesContent":["import * as Agenda from 'agenda';\nimport * as logger from 'winston';\nimport { PluginManager } from '../plugin.manager';\n\nexport abstract class Job {\n    public enabled: boolean = false;\n    public inited: boolean = false;\n    protected jobExecutor: Agenda;\n\n    constructor(protected pluginManager: PluginManager) {\n        this.jobExecutor = this.pluginManager.getJobExecutor();\n        this.jobExecutor.define(this.getJobId(), async (job, done) => {\n            logger.info(`${this.getJobId()}: executing job`);\n\n            if (!this.inited) {\n                logger.warn(`${this.getJobId()}: was not initialized, initializing`);\n\n                await this.init();\n\n                this.inited = true;\n\n                logger.warn(`${this.getJobId()}: was finally initialized`);\n            }\n\n            try {\n                await this.execute(job);\n                logger.info(`Job '${this.getJobId()}' executed`);\n                done();\n            }\n            catch (err) {\n                logger.error(`Job '${this.getJobId()}' of type ${this.constructor.name} failed to execute`, err);\n                done(err);\n            }\n        });\n    }\n\n    public abstract getJobId(): string;\n    public abstract async execute(job: Agenda.Job): Promise<void>;\n\n    public async init(): Promise<void> {\n        this.inited = true;\n    }\n\n    public async touch(job: Agenda.Job): Promise<any> {\n        return new Promise((resolve, reject) => {\n            job.touch((err) => {\n                if (err) {\n                    reject(err);\n                } else {\n                    resolve();\n                }\n            });\n        });\n    }\n}\n"]}