@open-mercato/scheduler 0.10.1-develop.7903.1.d8ab1c8b0d → 0.10.1-develop.7916.1.586cee8389
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -167,7 +167,7 @@ const startCommand = {
|
|
|
167
167
|
writeLine("");
|
|
168
168
|
writeLine("BullMQ is managing all schedules.");
|
|
169
169
|
writeLine("Start workers to process jobs:");
|
|
170
|
-
writeLine(" yarn mercato worker
|
|
170
|
+
writeLine(" yarn mercato queue worker --all");
|
|
171
171
|
writeLine("");
|
|
172
172
|
} catch (error) {
|
|
173
173
|
writeErrorLine(`\u274C Failed to sync schedules: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/modules/scheduler/cli.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ModuleCli } from '@open-mercato/shared/modules/registry'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { EntityManager } from '@mikro-orm/core'\nimport { ScheduledJob } from './data/entities.js'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\nimport { auditSchedulerModuleQueueRows } from './lib/safeQueueTargets'\nimport { createQueue } from '@open-mercato/queue'\nimport type { Queue } from '@open-mercato/queue'\nimport { getRedisUrlOrThrow } from '@open-mercato/shared/lib/redis/connection'\nimport type { ExecuteSchedulePayload } from './workers/execute-schedule.worker.js'\n\nconst writeLine = (text = '') => {\n process.stdout.write(`${text}\\n`)\n}\n\nconst writeErrorLine = (text: string) => {\n process.stderr.write(`${text}\\n`)\n}\n\nfunction parseArgs(rest: string[]): Record<string, string> {\n const args: Record<string, string> = {}\n for (let i = 0; i < rest.length; i += 2) {\n const key = rest[i]?.replace(/^--/, '')\n const value = rest[i + 1]\n if (key) args[key] = value ?? ''\n }\n return args\n}\n\nconst listCommand: ModuleCli = {\n command: 'list',\n async run(rest) {\n const args = parseArgs(rest)\n const { resolve } = await createRequestContainer()\n const em = resolve('em') as EntityManager\n\n const where: Record<string, unknown> = { deletedAt: null }\n\n // Filter by tenant if provided\n if (args.tenant || args.tenantId) {\n where.tenantId = args.tenant || args.tenantId\n }\n\n // Filter by scope type if provided\n if (args.scope || args.scopeType) {\n where.scopeType = args.scope || args.scopeType\n }\n\n // Filter by enabled status if provided\n if (args.enabled) {\n const parsed = parseBooleanToken(args.enabled)\n if (parsed !== null) {\n where.isEnabled = parsed\n }\n }\n\n const jobs = await em.find(ScheduledJob, where, {\n orderBy: { isEnabled: 'DESC', name: 'ASC' },\n })\n\n if (jobs.length === 0) {\n writeLine('No scheduled jobs found.')\n return\n }\n\n writeLine(`\\nFound ${jobs.length} scheduled job(s):\\n`)\n writeLine('ID'.padEnd(38) + 'Name'.padEnd(35) + 'Type'.padEnd(12) + 'Schedule'.padEnd(20) + 'Status'.padEnd(10) + 'Next Run')\n writeLine('-'.repeat(140))\n\n for (const job of jobs) {\n const id = String(job.id).padEnd(38)\n const name = (job.name || '').substring(0, 33).padEnd(35)\n const type = job.scheduleType.padEnd(12)\n const schedule = (job.scheduleValue || '').substring(0, 18).padEnd(20)\n const status = (job.isEnabled ? '\u2713 Enabled' : '\u2717 Disabled').padEnd(10)\n const nextRun = job.nextRunAt ? new Date(job.nextRunAt).toISOString() : 'N/A'\n writeLine(`${id}${name}${type}${schedule}${status}${nextRun}`)\n }\n\n writeLine('')\n },\n}\n\nconst statusCommand: ModuleCli = {\n command: 'status',\n async run() {\n const { resolve } = await createRequestContainer()\n const em = resolve('em') as EntityManager\n\n const totalCount = await em.count(ScheduledJob, { deletedAt: null })\n const enabledCount = await em.count(ScheduledJob, { isEnabled: true, deletedAt: null })\n const dueCount = await em.count(ScheduledJob, {\n isEnabled: true,\n deletedAt: null,\n nextRunAt: { $lte: new Date() },\n })\n\n const queueStrategy = process.env.QUEUE_STRATEGY || 'local'\n\n writeLine('\\n\uD83D\uDCCA Scheduler Status\\n')\n writeLine(`Strategy: ${queueStrategy === 'async' ? 'BullMQ (async)' : 'Local (polling)'}`)\n \n if (queueStrategy === 'local') {\n const pollInterval = parseInt(process.env.SCHEDULER_POLL_INTERVAL_MS || '30000', 10)\n writeLine(`Poll Interval: ${Math.round(pollInterval / 1000)}s`)\n }\n \n writeLine('')\n writeLine('Schedules:')\n writeLine(` Total: ${totalCount}`)\n writeLine(` Enabled: ${enabledCount}`)\n writeLine(` Due Now: ${dueCount}`)\n writeLine('')\n },\n}\n\nconst runCommand: ModuleCli = {\n command: 'run',\n async run(rest) {\n const scheduleId = rest[0]\n if (!scheduleId) {\n writeErrorLine('Usage: mercato scheduler run <schedule-id>')\n process.exitCode = 1\n return\n }\n\n const { resolve } = await createRequestContainer()\n const em = resolve('em') as EntityManager\n\n const job = await em.findOne(ScheduledJob, { id: scheduleId, deletedAt: null })\n if (!job) {\n writeErrorLine(`Schedule not found: ${scheduleId}`)\n process.exitCode = 1\n return\n }\n\n writeLine(`\\n\uD83D\uDE80 Manually triggering schedule: ${job.name}\\n`)\n writeLine(` ID: ${job.id}`)\n writeLine(` Type: ${job.scheduleType}`)\n writeLine(` Schedule: ${job.scheduleValue}`)\n writeLine(` Target: ${job.targetType === 'queue' ? job.targetQueue : job.targetCommand}`)\n writeLine('')\n\n // Mirrors scheduler.jobs.trigger: under the local strategy nothing consumes scheduler-execution.\n if ((process.env.QUEUE_STRATEGY || 'local') !== 'async') {\n throw new Error(\n 'Manual trigger requires QUEUE_STRATEGY=async (with the local strategy due schedules run via `mercato scheduler start`)',\n )\n }\n\n const payload: ExecuteSchedulePayload = {\n scheduleId: job.id,\n tenantId: job.tenantId,\n organizationId: job.organizationId,\n scopeType: job.scopeType,\n triggerType: 'manual',\n triggeredByUserId: null,\n }\n\n let executionQueue: Queue<ExecuteSchedulePayload> | null = null\n try {\n executionQueue = createQueue<ExecuteSchedulePayload>('scheduler-execution', 'async', {\n connection: { url: getRedisUrlOrThrow('QUEUE') },\n })\n const queueJobId = await executionQueue.enqueue(payload)\n\n writeLine(`\u2713 Job successfully triggered via scheduler-execution queue (job ${queueJobId})`)\n writeLine(` The worker will pick it up and enqueue to: ${job.targetType === 'queue' ? job.targetQueue : job.targetCommand}`)\n writeLine('\u2713 Manual trigger completed\\n')\n } catch (error: unknown) {\n throw new Error(`Failed to trigger job: ${error instanceof Error ? error.message : String(error)}`)\n } finally {\n await executionQueue?.close().catch((closeError: unknown) => {\n writeErrorLine(`Failed to close scheduler execution queue: ${closeError instanceof Error ? closeError.message : String(closeError)}`)\n })\n }\n },\n}\n\nconst startCommand: ModuleCli = {\n command: 'start',\n async run() {\n const { resolve } = await createRequestContainer()\n const queueStrategy = process.env.QUEUE_STRATEGY || 'local'\n\n writeLine(`\uD83D\uDE80 Starting scheduler (strategy: ${queueStrategy})...\\n`)\n\n if (queueStrategy === 'async') {\n // BullMQ strategy: Sync schedules with BullMQ repeatable jobs\n try {\n const bullmqService = resolve('bullmqSchedulerService') as { syncAll(): Promise<void> } | undefined\n \n if (!bullmqService) {\n writeErrorLine('\u274C BullMQSchedulerService not available.')\n writeErrorLine(' Set QUEUE_STRATEGY=async and configure REDIS_URL.')\n process.exit(1)\n }\n\n // Sync all enabled schedules with BullMQ\n await bullmqService.syncAll()\n\n writeLine('\u2713 Scheduler sync completed')\n writeLine('')\n writeLine('BullMQ is managing all schedules.')\n writeLine('Start workers to process jobs:')\n writeLine(' yarn mercato worker:start')\n writeLine('')\n } catch (error: unknown) {\n writeErrorLine(`\u274C Failed to sync schedules: ${error instanceof Error ? error.message : String(error)}`)\n process.exit(1)\n }\n } else {\n // Local strategy: Start polling engine\n try {\n const localService = resolve('localSchedulerService') as { start(): Promise<void>; stop(): Promise<void> } | undefined\n \n if (!localService) {\n writeErrorLine('\u274C LocalSchedulerService not available.')\n writeErrorLine(' This should not happen in local mode.')\n process.exit(1)\n }\n\n const pollInterval = parseInt(process.env.SCHEDULER_POLL_INTERVAL_MS || '30000', 10)\n\n // Start the local polling engine\n await localService.start()\n\n writeLine(`\u2713 Local scheduler started (polling every ${Math.round(pollInterval / 1000)} seconds)`)\n writeLine('Press Ctrl+C to stop.')\n writeLine('')\n writeLine('\uD83D\uDCA1 Tip: For production, use QUEUE_STRATEGY=async with Redis.')\n writeLine('')\n\n // Keep the process alive and handle graceful shutdown\n const gracefulShutdown = async () => {\n writeLine('\\n\uD83D\uDCDB Shutting down...')\n await localService.stop()\n writeLine('\u2713 Stopped')\n process.exit(0)\n }\n\n process.on('SIGINT', gracefulShutdown)\n process.on('SIGTERM', gracefulShutdown)\n\n // Keep process alive\n await new Promise(() => {}) // Never resolves\n } catch (error: unknown) {\n writeErrorLine(`\u274C Failed to start local scheduler: ${error instanceof Error ? error.message : String(error)}`)\n process.exit(1)\n }\n }\n },\n}\n\n// Lists every persisted module-authored queue-target row with its current\n// dispatch verdict (#5213). Rows authored before the hardening by a\n// non-user-bound API key are indistinguishable from genuine registrations at\n// rest, so operators review the ALLOWED entries against their known integrations.\nconst auditQueueTargetsCommand: ModuleCli = {\n command: 'audit-queue-targets',\n async run(rest) {\n const args = parseArgs(rest)\n const { resolve } = await createRequestContainer()\n const em = resolve('em') as EntityManager\n\n const where: Record<string, unknown> = { deletedAt: null, sourceType: 'module' }\n if (args.tenant || args.tenantId) where.tenantId = args.tenant || args.tenantId\n\n const rows = await em.find(ScheduledJob, where, {\n orderBy: { name: 'ASC' },\n })\n\n const audits = auditSchedulerModuleQueueRows(rows)\n\n writeLine(`Module-authored queue-target schedules: ${audits.length}`)\n let allowedCount = 0\n for (const audit of audits) {\n const verdict = audit.dispatchAllowed ? 'ALLOWED' : 'blocked'\n if (audit.dispatchAllowed) allowedCount += 1\n writeLine(\n `[${verdict}] ${audit.scheduleId}${audit.name ? ` \u2014 ${audit.name}` : ''}` +\n ` module=${audit.sourceModule ?? '(none)'} queue=${audit.targetQueue ?? '(none)'}` +\n ` enabled=${audit.isEnabled ? 'yes' : 'no'}`,\n )\n }\n\n if (allowedCount > 0) {\n writeLine('')\n writeLine(`Review the ${allowedCount} ALLOWED row(s) above against your known module integrations.`)\n writeLine('Pre-upgrade rows created with a non-user-bound API key cannot be distinguished')\n writeLine('from genuine registrations at rest; disable anything unrecognized:')\n writeLine(' yarn mercato scheduler list --tenant <tenantId>')\n }\n },\n}\n\nexport default [listCommand, statusCommand, runCommand, startCommand, auditQueueTargetsCommand]\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,8BAA8B;AAEvC,SAAS,oBAAoB;AAC7B,SAAS,yBAAyB;AAClC,SAAS,qCAAqC;AAC9C,SAAS,mBAAmB;AAE5B,SAAS,0BAA0B;AAGnC,MAAM,YAAY,CAAC,OAAO,OAAO;AAC/B,UAAQ,OAAO,MAAM,GAAG,IAAI;AAAA,CAAI;AAClC;AAEA,MAAM,iBAAiB,CAAC,SAAiB;AACvC,UAAQ,OAAO,MAAM,GAAG,IAAI;AAAA,CAAI;AAClC;AAEA,SAAS,UAAU,MAAwC;AACzD,QAAM,OAA+B,CAAC;AACtC,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,GAAG;AACvC,UAAM,MAAM,KAAK,CAAC,GAAG,QAAQ,OAAO,EAAE;AACtC,UAAM,QAAQ,KAAK,IAAI,CAAC;AACxB,QAAI,IAAK,MAAK,GAAG,IAAI,SAAS;AAAA,EAChC;AACA,SAAO;AACT;AAEA,MAAM,cAAyB;AAAA,EAC7B,SAAS;AAAA,EACT,MAAM,IAAI,MAAM;AACd,UAAM,OAAO,UAAU,IAAI;AAC3B,UAAM,EAAE,QAAQ,IAAI,MAAM,uBAAuB;AACjD,UAAM,KAAK,QAAQ,IAAI;AAEvB,UAAM,QAAiC,EAAE,WAAW,KAAK;AAGzD,QAAI,KAAK,UAAU,KAAK,UAAU;AAChC,YAAM,WAAW,KAAK,UAAU,KAAK;AAAA,IACvC;AAGA,QAAI,KAAK,SAAS,KAAK,WAAW;AAChC,YAAM,YAAY,KAAK,SAAS,KAAK;AAAA,IACvC;AAGA,QAAI,KAAK,SAAS;AAChB,Y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gBAAgB,QAAQ,wBAAwB;AAEtD,YAAI,CAAC,eAAe;AAClB,yBAAe,8CAAyC;AACxD,yBAAe,sDAAsD;AACrE,kBAAQ,KAAK,CAAC;AAAA,QAChB;AAGA,cAAM,cAAc,QAAQ;AAE5B,kBAAU,iCAA4B;AACtC,kBAAU,EAAE;AACZ,kBAAU,mCAAmC;AAC7C,kBAAU,gCAAgC;AAC1C,kBAAU,
|
|
4
|
+
"sourcesContent": ["import type { ModuleCli } from '@open-mercato/shared/modules/registry'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { EntityManager } from '@mikro-orm/core'\nimport { ScheduledJob } from './data/entities.js'\nimport { parseBooleanToken } from '@open-mercato/shared/lib/boolean'\nimport { auditSchedulerModuleQueueRows } from './lib/safeQueueTargets'\nimport { createQueue } from '@open-mercato/queue'\nimport type { Queue } from '@open-mercato/queue'\nimport { getRedisUrlOrThrow } from '@open-mercato/shared/lib/redis/connection'\nimport type { ExecuteSchedulePayload } from './workers/execute-schedule.worker.js'\n\nconst writeLine = (text = '') => {\n process.stdout.write(`${text}\\n`)\n}\n\nconst writeErrorLine = (text: string) => {\n process.stderr.write(`${text}\\n`)\n}\n\nfunction parseArgs(rest: string[]): Record<string, string> {\n const args: Record<string, string> = {}\n for (let i = 0; i < rest.length; i += 2) {\n const key = rest[i]?.replace(/^--/, '')\n const value = rest[i + 1]\n if (key) args[key] = value ?? ''\n }\n return args\n}\n\nconst listCommand: ModuleCli = {\n command: 'list',\n async run(rest) {\n const args = parseArgs(rest)\n const { resolve } = await createRequestContainer()\n const em = resolve('em') as EntityManager\n\n const where: Record<string, unknown> = { deletedAt: null }\n\n // Filter by tenant if provided\n if (args.tenant || args.tenantId) {\n where.tenantId = args.tenant || args.tenantId\n }\n\n // Filter by scope type if provided\n if (args.scope || args.scopeType) {\n where.scopeType = args.scope || args.scopeType\n }\n\n // Filter by enabled status if provided\n if (args.enabled) {\n const parsed = parseBooleanToken(args.enabled)\n if (parsed !== null) {\n where.isEnabled = parsed\n }\n }\n\n const jobs = await em.find(ScheduledJob, where, {\n orderBy: { isEnabled: 'DESC', name: 'ASC' },\n })\n\n if (jobs.length === 0) {\n writeLine('No scheduled jobs found.')\n return\n }\n\n writeLine(`\\nFound ${jobs.length} scheduled job(s):\\n`)\n writeLine('ID'.padEnd(38) + 'Name'.padEnd(35) + 'Type'.padEnd(12) + 'Schedule'.padEnd(20) + 'Status'.padEnd(10) + 'Next Run')\n writeLine('-'.repeat(140))\n\n for (const job of jobs) {\n const id = String(job.id).padEnd(38)\n const name = (job.name || '').substring(0, 33).padEnd(35)\n const type = job.scheduleType.padEnd(12)\n const schedule = (job.scheduleValue || '').substring(0, 18).padEnd(20)\n const status = (job.isEnabled ? '\u2713 Enabled' : '\u2717 Disabled').padEnd(10)\n const nextRun = job.nextRunAt ? new Date(job.nextRunAt).toISOString() : 'N/A'\n writeLine(`${id}${name}${type}${schedule}${status}${nextRun}`)\n }\n\n writeLine('')\n },\n}\n\nconst statusCommand: ModuleCli = {\n command: 'status',\n async run() {\n const { resolve } = await createRequestContainer()\n const em = resolve('em') as EntityManager\n\n const totalCount = await em.count(ScheduledJob, { deletedAt: null })\n const enabledCount = await em.count(ScheduledJob, { isEnabled: true, deletedAt: null })\n const dueCount = await em.count(ScheduledJob, {\n isEnabled: true,\n deletedAt: null,\n nextRunAt: { $lte: new Date() },\n })\n\n const queueStrategy = process.env.QUEUE_STRATEGY || 'local'\n\n writeLine('\\n\uD83D\uDCCA Scheduler Status\\n')\n writeLine(`Strategy: ${queueStrategy === 'async' ? 'BullMQ (async)' : 'Local (polling)'}`)\n \n if (queueStrategy === 'local') {\n const pollInterval = parseInt(process.env.SCHEDULER_POLL_INTERVAL_MS || '30000', 10)\n writeLine(`Poll Interval: ${Math.round(pollInterval / 1000)}s`)\n }\n \n writeLine('')\n writeLine('Schedules:')\n writeLine(` Total: ${totalCount}`)\n writeLine(` Enabled: ${enabledCount}`)\n writeLine(` Due Now: ${dueCount}`)\n writeLine('')\n },\n}\n\nconst runCommand: ModuleCli = {\n command: 'run',\n async run(rest) {\n const scheduleId = rest[0]\n if (!scheduleId) {\n writeErrorLine('Usage: mercato scheduler run <schedule-id>')\n process.exitCode = 1\n return\n }\n\n const { resolve } = await createRequestContainer()\n const em = resolve('em') as EntityManager\n\n const job = await em.findOne(ScheduledJob, { id: scheduleId, deletedAt: null })\n if (!job) {\n writeErrorLine(`Schedule not found: ${scheduleId}`)\n process.exitCode = 1\n return\n }\n\n writeLine(`\\n\uD83D\uDE80 Manually triggering schedule: ${job.name}\\n`)\n writeLine(` ID: ${job.id}`)\n writeLine(` Type: ${job.scheduleType}`)\n writeLine(` Schedule: ${job.scheduleValue}`)\n writeLine(` Target: ${job.targetType === 'queue' ? job.targetQueue : job.targetCommand}`)\n writeLine('')\n\n // Mirrors scheduler.jobs.trigger: under the local strategy nothing consumes scheduler-execution.\n if ((process.env.QUEUE_STRATEGY || 'local') !== 'async') {\n throw new Error(\n 'Manual trigger requires QUEUE_STRATEGY=async (with the local strategy due schedules run via `mercato scheduler start`)',\n )\n }\n\n const payload: ExecuteSchedulePayload = {\n scheduleId: job.id,\n tenantId: job.tenantId,\n organizationId: job.organizationId,\n scopeType: job.scopeType,\n triggerType: 'manual',\n triggeredByUserId: null,\n }\n\n let executionQueue: Queue<ExecuteSchedulePayload> | null = null\n try {\n executionQueue = createQueue<ExecuteSchedulePayload>('scheduler-execution', 'async', {\n connection: { url: getRedisUrlOrThrow('QUEUE') },\n })\n const queueJobId = await executionQueue.enqueue(payload)\n\n writeLine(`\u2713 Job successfully triggered via scheduler-execution queue (job ${queueJobId})`)\n writeLine(` The worker will pick it up and enqueue to: ${job.targetType === 'queue' ? job.targetQueue : job.targetCommand}`)\n writeLine('\u2713 Manual trigger completed\\n')\n } catch (error: unknown) {\n throw new Error(`Failed to trigger job: ${error instanceof Error ? error.message : String(error)}`)\n } finally {\n await executionQueue?.close().catch((closeError: unknown) => {\n writeErrorLine(`Failed to close scheduler execution queue: ${closeError instanceof Error ? closeError.message : String(closeError)}`)\n })\n }\n },\n}\n\nconst startCommand: ModuleCli = {\n command: 'start',\n async run() {\n const { resolve } = await createRequestContainer()\n const queueStrategy = process.env.QUEUE_STRATEGY || 'local'\n\n writeLine(`\uD83D\uDE80 Starting scheduler (strategy: ${queueStrategy})...\\n`)\n\n if (queueStrategy === 'async') {\n // BullMQ strategy: Sync schedules with BullMQ repeatable jobs\n try {\n const bullmqService = resolve('bullmqSchedulerService') as { syncAll(): Promise<void> } | undefined\n \n if (!bullmqService) {\n writeErrorLine('\u274C BullMQSchedulerService not available.')\n writeErrorLine(' Set QUEUE_STRATEGY=async and configure REDIS_URL.')\n process.exit(1)\n }\n\n // Sync all enabled schedules with BullMQ\n await bullmqService.syncAll()\n\n writeLine('\u2713 Scheduler sync completed')\n writeLine('')\n writeLine('BullMQ is managing all schedules.')\n writeLine('Start workers to process jobs:')\n writeLine(' yarn mercato queue worker --all')\n writeLine('')\n } catch (error: unknown) {\n writeErrorLine(`\u274C Failed to sync schedules: ${error instanceof Error ? error.message : String(error)}`)\n process.exit(1)\n }\n } else {\n // Local strategy: Start polling engine\n try {\n const localService = resolve('localSchedulerService') as { start(): Promise<void>; stop(): Promise<void> } | undefined\n \n if (!localService) {\n writeErrorLine('\u274C LocalSchedulerService not available.')\n writeErrorLine(' This should not happen in local mode.')\n process.exit(1)\n }\n\n const pollInterval = parseInt(process.env.SCHEDULER_POLL_INTERVAL_MS || '30000', 10)\n\n // Start the local polling engine\n await localService.start()\n\n writeLine(`\u2713 Local scheduler started (polling every ${Math.round(pollInterval / 1000)} seconds)`)\n writeLine('Press Ctrl+C to stop.')\n writeLine('')\n writeLine('\uD83D\uDCA1 Tip: For production, use QUEUE_STRATEGY=async with Redis.')\n writeLine('')\n\n // Keep the process alive and handle graceful shutdown\n const gracefulShutdown = async () => {\n writeLine('\\n\uD83D\uDCDB Shutting down...')\n await localService.stop()\n writeLine('\u2713 Stopped')\n process.exit(0)\n }\n\n process.on('SIGINT', gracefulShutdown)\n process.on('SIGTERM', gracefulShutdown)\n\n // Keep process alive\n await new Promise(() => {}) // Never resolves\n } catch (error: unknown) {\n writeErrorLine(`\u274C Failed to start local scheduler: ${error instanceof Error ? error.message : String(error)}`)\n process.exit(1)\n }\n }\n },\n}\n\n// Lists every persisted module-authored queue-target row with its current\n// dispatch verdict (#5213). Rows authored before the hardening by a\n// non-user-bound API key are indistinguishable from genuine registrations at\n// rest, so operators review the ALLOWED entries against their known integrations.\nconst auditQueueTargetsCommand: ModuleCli = {\n command: 'audit-queue-targets',\n async run(rest) {\n const args = parseArgs(rest)\n const { resolve } = await createRequestContainer()\n const em = resolve('em') as EntityManager\n\n const where: Record<string, unknown> = { deletedAt: null, sourceType: 'module' }\n if (args.tenant || args.tenantId) where.tenantId = args.tenant || args.tenantId\n\n const rows = await em.find(ScheduledJob, where, {\n orderBy: { name: 'ASC' },\n })\n\n const audits = auditSchedulerModuleQueueRows(rows)\n\n writeLine(`Module-authored queue-target schedules: ${audits.length}`)\n let allowedCount = 0\n for (const audit of audits) {\n const verdict = audit.dispatchAllowed ? 'ALLOWED' : 'blocked'\n if (audit.dispatchAllowed) allowedCount += 1\n writeLine(\n `[${verdict}] ${audit.scheduleId}${audit.name ? ` \u2014 ${audit.name}` : ''}` +\n ` module=${audit.sourceModule ?? '(none)'} queue=${audit.targetQueue ?? '(none)'}` +\n ` enabled=${audit.isEnabled ? 'yes' : 'no'}`,\n )\n }\n\n if (allowedCount > 0) {\n writeLine('')\n writeLine(`Review the ${allowedCount} ALLOWED row(s) above against your known module integrations.`)\n writeLine('Pre-upgrade rows created with a non-user-bound API key cannot be distinguished')\n writeLine('from genuine registrations at rest; disable anything unrecognized:')\n writeLine(' yarn mercato scheduler list --tenant <tenantId>')\n }\n },\n}\n\nexport default [listCommand, statusCommand, runCommand, startCommand, auditQueueTargetsCommand]\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,8BAA8B;AAEvC,SAAS,oBAAoB;AAC7B,SAAS,y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AAEvE,UAAM,OAAO,MAAM,GAAG,KAAK,cAAc,OAAO;AAAA,MAC9C,SAAS,EAAE,MAAM,MAAM;AAAA,IACzB,CAAC;AAED,UAAM,SAAS,8BAA8B,IAAI;AAEjD,cAAU,2CAA2C,OAAO,MAAM,EAAE;AACpE,QAAI,eAAe;AACnB,eAAW,SAAS,QAAQ;AAC1B,YAAM,UAAU,MAAM,kBAAkB,YAAY;AACpD,UAAI,MAAM,gBAAiB,iBAAgB;AAC3C;AAAA,QACE,IAAI,OAAO,KAAK,MAAM,UAAU,GAAG,MAAM,OAAO,WAAM,MAAM,IAAI,KAAK,EAAE,WAC5D,MAAM,gBAAgB,QAAQ,UAAU,MAAM,eAAe,QAAQ,YACpE,MAAM,YAAY,QAAQ,IAAI;AAAA,MAC5C;AAAA,IACF;AAEA,QAAI,eAAe,GAAG;AACpB,gBAAU,EAAE;AACZ,gBAAU,cAAc,YAAY,+DAA+D;AACnG,gBAAU,gFAAgF;AAC1F,gBAAU,oEAAoE;AAC9E,gBAAU,mDAAmD;AAAA,IAC/D;AAAA,EACF;AACF;AAEA,IAAO,cAAQ,CAAC,aAAa,eAAe,YAAY,cAAc,wBAAwB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/scheduler",
|
|
3
|
-
"version": "0.10.1-develop.
|
|
3
|
+
"version": "0.10.1-develop.7916.1.586cee8389",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Database-managed scheduled jobs with admin UI",
|
|
6
6
|
"type": "module",
|
|
@@ -59,13 +59,13 @@
|
|
|
59
59
|
"./*/*/*/*/*/*.json": "./src/*/*/*/*/*/*.json"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@open-mercato/events": "0.10.1-develop.
|
|
63
|
-
"@open-mercato/queue": "0.10.1-develop.
|
|
62
|
+
"@open-mercato/events": "0.10.1-develop.7916.1.586cee8389",
|
|
63
|
+
"@open-mercato/queue": "0.10.1-develop.7916.1.586cee8389",
|
|
64
64
|
"cron-parser": "^5.6.2"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@mikro-orm/core": "^7.0.14",
|
|
68
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
68
|
+
"@open-mercato/shared": "0.10.1-develop.7916.1.586cee8389",
|
|
69
69
|
"bullmq": "^5.0.0 || ^6.0.0",
|
|
70
70
|
"ioredis": "^5.0.0 || ^6.0.0",
|
|
71
71
|
"zod": ">=3.23.0"
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
82
|
+
"@open-mercato/shared": "0.10.1-develop.7916.1.586cee8389",
|
|
83
83
|
"@types/jest": "^30.0.0",
|
|
84
84
|
"@types/node": "^26.4.0",
|
|
85
85
|
"jest": "^30.4.2",
|
|
@@ -133,3 +133,44 @@ describe('mercato scheduler run', () => {
|
|
|
133
133
|
expect(close).toHaveBeenCalledTimes(1)
|
|
134
134
|
})
|
|
135
135
|
})
|
|
136
|
+
|
|
137
|
+
function loadStartCommand() {
|
|
138
|
+
let commands: Array<{ command: string; run(rest: string[]): Promise<void> }> = []
|
|
139
|
+
jest.isolateModules(() => {
|
|
140
|
+
commands = require('../cli').default
|
|
141
|
+
})
|
|
142
|
+
const start = commands.find((cmd) => cmd.command === 'start')
|
|
143
|
+
if (!start) throw new Error('start command not registered')
|
|
144
|
+
return start
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
describe('mercato scheduler start', () => {
|
|
148
|
+
const previousStrategy = process.env.QUEUE_STRATEGY
|
|
149
|
+
const syncAll = jest.fn()
|
|
150
|
+
let stdout: jest.SpyInstance
|
|
151
|
+
|
|
152
|
+
beforeEach(() => {
|
|
153
|
+
jest.clearAllMocks()
|
|
154
|
+
syncAll.mockResolvedValue(undefined)
|
|
155
|
+
resolve.mockImplementationOnce(() => ({ syncAll }))
|
|
156
|
+
stdout = jest.spyOn(process.stdout, 'write').mockImplementation(() => true)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
afterEach(() => {
|
|
160
|
+
stdout.mockRestore()
|
|
161
|
+
if (previousStrategy === undefined) delete process.env.QUEUE_STRATEGY
|
|
162
|
+
else process.env.QUEUE_STRATEGY = previousStrategy
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
it('points operators at the real queue worker command after an async sync', async () => {
|
|
166
|
+
process.env.QUEUE_STRATEGY = 'async'
|
|
167
|
+
|
|
168
|
+
await loadStartCommand().run([])
|
|
169
|
+
|
|
170
|
+
const output = stdout.mock.calls.map(([chunk]) => String(chunk)).join('')
|
|
171
|
+
expect(resolve).toHaveBeenCalledWith('bullmqSchedulerService')
|
|
172
|
+
expect(syncAll).toHaveBeenCalledTimes(1)
|
|
173
|
+
expect(output).toContain(' yarn mercato queue worker --all\n')
|
|
174
|
+
expect(output).not.toContain('worker:start')
|
|
175
|
+
})
|
|
176
|
+
})
|
|
@@ -203,7 +203,7 @@ const startCommand: ModuleCli = {
|
|
|
203
203
|
writeLine('')
|
|
204
204
|
writeLine('BullMQ is managing all schedules.')
|
|
205
205
|
writeLine('Start workers to process jobs:')
|
|
206
|
-
writeLine(' yarn mercato worker
|
|
206
|
+
writeLine(' yarn mercato queue worker --all')
|
|
207
207
|
writeLine('')
|
|
208
208
|
} catch (error: unknown) {
|
|
209
209
|
writeErrorLine(`❌ Failed to sync schedules: ${error instanceof Error ? error.message : String(error)}`)
|