diff --git a/plugins/wazuh-core/server/services/initialization/initialization.ts b/plugins/wazuh-core/server/services/initialization/initialization.ts index f47ae76c97..636ef63192 100644 --- a/plugins/wazuh-core/server/services/initialization/initialization.ts +++ b/plugins/wazuh-core/server/services/initialization/initialization.ts @@ -5,7 +5,7 @@ import { InitializationTaskContext, } from './types'; import { addRoutes } from './routes'; -import { INITIALIZATION_TASK_CONTEXT_INTERNAL } from '../../../common/services/initialization/constants'; +import { INITIALIZATION_TASK } from '../../../common/services/initialization/constants'; import { InitializationTask } from './lib/initialization-task'; export class InitializationService implements IInitializationService { @@ -57,7 +57,7 @@ export class InitializationService implements IInitializationService { return { ...this.services, ...context, scope }; } async runAsInternal(taskNames?: string[]) { - const ctx = this.createRunContext(INITIALIZATION_TASK_CONTEXT_INTERNAL, { + const ctx = this.createRunContext(INITIALIZATION_TASK.CONTEXT.INTERNAL, { core: this._coreStart, }); return await this.run(ctx, taskNames); diff --git a/plugins/wazuh-core/server/services/initialization/lib/initialization-task.ts b/plugins/wazuh-core/server/services/initialization/lib/initialization-task.ts index 166d294e45..a6c00c71fd 100644 --- a/plugins/wazuh-core/server/services/initialization/lib/initialization-task.ts +++ b/plugins/wazuh-core/server/services/initialization/lib/initialization-task.ts @@ -3,22 +3,15 @@ import { InitializationTaskRunData, IInitializationTask, } from '../types'; -import { - INITIALIZATION_TASK_RUN_RESULT_FAIL, - INITIALIZATION_TASK_RUN_RESULT_NULL, - INITIALIZATION_TASK_RUN_RESULT_SUCCESS, - INITIALIZATION_TASK_RUN_STATUS_FINISHED, - INITIALIZATION_TASK_RUN_STATUS_NOT_STARTED, - INITIALIZATION_TASK_RUN_STATUS_RUNNING, -} from '../../../../common/services/initialization/constants'; +import { INITIALIZATION_TASK } from '../../../../common/services/initialization/constants'; export class InitializationTask implements IInitializationTask { public name: string; private _run: any; public status: InitializationTaskRunData['status'] = - INITIALIZATION_TASK_RUN_STATUS_NOT_STARTED; + INITIALIZATION_TASK.RUN_STATUS.NOT_STARTED; public result: InitializationTaskRunData['result'] = - INITIALIZATION_TASK_RUN_RESULT_NULL; + INITIALIZATION_TASK.RUN_RESULT.NULL; public data: any = null; public createdAt: InitializationTaskRunData['createdAt'] = new Date().toISOString(); @@ -31,7 +24,7 @@ export class InitializationTask implements IInitializationTask { this._run = task.run; } private init() { - this.status = INITIALIZATION_TASK_RUN_STATUS_RUNNING; + this.status = INITIALIZATION_TASK.RUN_STATUS.RUNNING; this.result = null; this.data = null; this.startedAt = new Date().toISOString(); @@ -40,20 +33,20 @@ export class InitializationTask implements IInitializationTask { this.error = null; } async run(...params) { - if (this.status === INITIALIZATION_TASK_RUN_STATUS_RUNNING) { + if (this.status === INITIALIZATION_TASK.RUN_STATUS.RUNNING) { throw new Error(`Another instance of task ${this.name} is running`); } let error; try { this.init(); this.data = await this._run(...params); - this.result = INITIALIZATION_TASK_RUN_RESULT_SUCCESS; + this.result = INITIALIZATION_TASK.RUN_RESULT.SUCCESS; } catch (e) { error = e; - this.result = INITIALIZATION_TASK_RUN_RESULT_FAIL; + this.result = INITIALIZATION_TASK.RUN_RESULT.FAIL; this.error = e.message; } finally { - this.status = INITIALIZATION_TASK_RUN_STATUS_FINISHED; + this.status = INITIALIZATION_TASK.RUN_STATUS.FINISHED; this.finishedAt = new Date().toISOString(); const dateStartedAt = new Date(this.startedAt!); const dateFinishedAt = new Date(this.finishedAt);