import { Ignitor } from '@adonisjs/core' const APP_ROOT = new URL('../../', import.meta.url) const IMPORTER = (filePath: string) => { if (filePath.startsWith('./') || filePath.startsWith('../')) { return import(new URL(filePath, APP_ROOT).href) } return import(filePath) } const ignitor = new Ignitor(APP_ROOT, { importer: IMPORTER }) const app = ignitor.createApp('web') await app.init() await app.boot() const SyncService = (await import('#services/sync_service')).default async function runSyncServiceTest() { const startedAt = Date.now() // syncFromErp giờ là orchestrator: chỉ quét ERP và enqueue job upsert lên BullMQ. // Việc upsert thực tế (và retry khi lỗi) do worker `node ace queue:work` xử lý. const summary = await SyncService.syncFromErp('tester', { pageSize: 100 }) console.log(`Enqueued ${summary.enqueued}/${summary.total} sản phẩm trong ${Date.now() - startedAt}ms`, summary) } await runSyncServiceTest()