@athenna/core
Version:
One foundation for multiple applications.
47 lines (46 loc) • 1.78 kB
JavaScript
/**
* @athenna/core
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { debug } from '#src/debug';
import { Log } from '@athenna/logger';
import { Path, Module, Options } from '@athenna/common';
export class Cron {
/**
* Boot the Cron application.
*/
static async boot(options) {
options = Options.create(options, {
trace: Config.get('cron.trace', false),
routePath: Path.routes(`cron.${Path.ext()}`),
kernelPath: '@athenna/cron/kernels/CronKernel'
});
const cron = ioc.safeUse('Athenna/Core/Cron');
debug('booting cron application with options %o', options);
await this.resolveKernel(options);
if (Config.notExists('rc.bootLogs') || Config.is('rc.bootLogs', false)) {
return cron;
}
Log.channelOrVanilla('application').success(`Cron application successfully started`);
return cron;
}
/**
* Resolve the kernel by importing it and calling the methods to register
* schedulers, plugins and exception handler.
*/
static async resolveKernel(options) {
const Kernel = await Module.resolve(options.kernelPath, Config.get('rc.parentURL'));
const kernel = new Kernel();
await kernel.registerRTracer(options.trace);
await kernel.registerExceptionHandler(options.exceptionHandlerPath);
await kernel.registerSchedulers();
await kernel.registerRoutes(options.routePath);
if (Config.is('rc.bootLogs', true)) {
Log.channelOrVanilla('application').success(`Kernel ({yellow} ${Kernel.name}) successfully booted`);
}
}
}