T-7: M0.3a — Harden dev Mongo safety: env-safety throws on unsafe data-pipeline QA reads, scheduled jobs default off, read-only bypass tests
This commit is contained in:
parent
7cf940afce
commit
abbab4b5a8
10 changed files with 644 additions and 18 deletions
|
|
@ -6,9 +6,13 @@ import type { HandlerRegistry } from '@stock-bot/handler-registry';
|
|||
import { defined } from '@stock-bot/invariants';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import type { LoggerLike as Logger } from '@stock-bot/logger';
|
||||
import { Queue, type QueueWorkerConfig } from './queue';
|
||||
import {
|
||||
Queue,
|
||||
removeScheduledJobsFromBullQueue,
|
||||
type QueueWorkerConfig,
|
||||
} from './queue';
|
||||
import { QueueRateLimiter } from './rate-limiter';
|
||||
import { getFullQueueName, parseQueueName } from './service-utils';
|
||||
import { getFullQueueName, normalizeServiceName, parseQueueName } from './service-utils';
|
||||
import type {
|
||||
GlobalStats,
|
||||
JobData,
|
||||
|
|
@ -558,6 +562,72 @@ export class QueueManager {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reconcile and remove persisted repeatable/scheduled jobs for the specified
|
||||
* handler queues owned by this service without starting workers.
|
||||
* Manual jobs and other services' queues are preserved.
|
||||
*/
|
||||
async removeScheduledJobsForQueues(queueNames: string[]): Promise<number> {
|
||||
this.assertConnectionsOpen();
|
||||
let totalRemoved = 0;
|
||||
const seenFullNames = new Set<string>();
|
||||
const normalizedService = this.serviceName
|
||||
? normalizeServiceName(this.serviceName)
|
||||
: undefined;
|
||||
|
||||
for (const rawQueueName of queueNames) {
|
||||
let fullQueueName = rawQueueName;
|
||||
let isOwnQueue = true;
|
||||
|
||||
if (this.serviceName) {
|
||||
const parsed = parseQueueName(rawQueueName);
|
||||
if (parsed) {
|
||||
fullQueueName = rawQueueName;
|
||||
isOwnQueue =
|
||||
parsed.service === this.serviceName || parsed.service === normalizedService;
|
||||
} else {
|
||||
fullQueueName = getFullQueueName(this.serviceName, rawQueueName);
|
||||
isOwnQueue = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isOwnQueue || seenFullNames.has(fullQueueName)) {
|
||||
continue;
|
||||
}
|
||||
seenFullNames.add(fullQueueName);
|
||||
|
||||
const existingQueue = this.queues.get(fullQueueName);
|
||||
if (existingQueue) {
|
||||
totalRemoved += await existingQueue.removeAllScheduledJobs();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Open a workerless BullQueue handle to clear persisted repeat schedules
|
||||
// before any worker can consume stale repeat jobs.
|
||||
const tempQueue = new BullQueue(fullQueueName, {
|
||||
connection: { ...this.redisConnection, maxRetriesPerRequest: 1, enableOfflineQueue: false },
|
||||
});
|
||||
try {
|
||||
totalRemoved += await removeScheduledJobsFromBullQueue(tempQueue);
|
||||
} finally {
|
||||
await tempQueue.close().catch(error => {
|
||||
this.logger.warn('Error closing temporary reconciliation queue', {
|
||||
queueName: fullQueueName,
|
||||
error,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.info('Reconciled disabled scheduled jobs for service queues', {
|
||||
service: this.serviceName || 'default',
|
||||
queueCount: seenFullNames.size,
|
||||
removedCount: totalRemoved,
|
||||
});
|
||||
|
||||
return totalRemoved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for all queues to be ready
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue