Explorar o código

feat(dashboard-plugin): Add build index task to global search configuration

- Introduced a new scheduled task for building the global search index.
- Updated the plugin configuration to include the new task.
- Refactored the task execution to utilize the scheduled context for better parameter handling.
David Höck hai 8 meses
pai
achega
f66995c60d

+ 1 - 0
package-lock.json

@@ -4897,6 +4897,7 @@
     },
     "node_modules/@clack/prompts/node_modules/is-unicode-supported": {
       "version": "1.3.0",
+      "extraneous": true,
       "inBundle": true,
       "license": "MIT",
       "engines": {

+ 2 - 1
packages/dashboard-plugin/src/plugin.ts

@@ -6,8 +6,8 @@ import { PLUGIN_INIT_OPTIONS } from './constants';
 import { GlobalSearchIndexItem } from './entities/global-search-index-item';
 import { IndexingService } from './service/indexing.service';
 import { SearchService } from './service/search.service';
+import { buildIndexTask } from './tasks/build-index.task';
 import { DashboardPluginOptions } from './types';
-
 /**
  * @description
  * This plugin adds functionality specifically required by the Vendure Admin Dashboard.
@@ -44,6 +44,7 @@ import { DashboardPluginOptions } from './types';
     entities: [GlobalSearchIndexItem],
     configuration: config => {
         // Plugin configuration logic here
+        config.schedulerOptions.tasks.push(buildIndexTask);
         return config;
     },
     compatibility: '^3.0.0',

+ 3 - 4
packages/dashboard-plugin/src/tasks/build-index.task.ts

@@ -1,5 +1,4 @@
-import { Injectable } from '@nestjs/common';
-import { Injector, ScheduledTask } from '@vendure/core';
+import { ScheduledTask } from '@vendure/core';
 
 import { IndexingService } from '../service/indexing.service';
 
@@ -7,8 +6,8 @@ export const buildIndexTask = new ScheduledTask({
     id: 'global-search-build-index',
     description: 'Builds the global search index',
     schedule: cron => cron.everyDayAt(2, 0),
-    execute: async (injector: Injector, params) => {
+    execute: async ({ injector, scheduledContext }) => {
         const indexingService = injector.get(IndexingService);
-        await indexingService.triggerBuildIndex(params.ctx);
+        await indexingService.triggerBuildIndex(scheduledContext);
     },
 });