reorder stop
This commit is contained in:
1 parent
dfae6c8abd
commit
f5a4a03898
1 file changed
+13
-4
@@ -27,6 +27,7 @@ export class LessSimpleQueue implements IJobQueue {
|
|||||||
private monitorsRepository: IMonitorsRepository;
|
private monitorsRepository: IMonitorsRepository;
|
||||||
private workersRepository: IQueueWorkersRepository;
|
private workersRepository: IQueueWorkersRepository;
|
||||||
private readonly scheduler: Scheduler;
|
private readonly scheduler: Scheduler;
|
||||||
|
private queueMode: QueueMode;
|
||||||
private heartbeatListener: ((workerId: string) => void) | null = null;
|
private heartbeatListener: ((workerId: string) => void) | null = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -34,13 +35,15 @@ export class LessSimpleQueue implements IJobQueue {
|
|||||||
helper: IQueueHelper,
|
helper: IQueueHelper,
|
||||||
monitorsRepository: IMonitorsRepository,
|
monitorsRepository: IMonitorsRepository,
|
||||||
workersRepository: IQueueWorkersRepository,
|
workersRepository: IQueueWorkersRepository,
|
||||||
scheduler: Scheduler
|
scheduler: Scheduler,
|
||||||
|
queueMode: QueueMode
|
||||||
) {
|
) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.helper = helper;
|
this.helper = helper;
|
||||||
this.monitorsRepository = monitorsRepository;
|
this.monitorsRepository = monitorsRepository;
|
||||||
this.workersRepository = workersRepository;
|
this.workersRepository = workersRepository;
|
||||||
this.scheduler = scheduler;
|
this.scheduler = scheduler;
|
||||||
|
this.queueMode = queueMode;
|
||||||
this.registerListeners();
|
this.registerListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +140,7 @@ export class LessSimpleQueue implements IJobQueue {
|
|||||||
const scheduler = new Scheduler(store, {
|
const scheduler = new Scheduler(store, {
|
||||||
concurrency: 50,
|
concurrency: 50,
|
||||||
});
|
});
|
||||||
const instance = new LessSimpleQueue(logger, helper, monitorsRepository, workersRepository, scheduler);
|
const instance = new LessSimpleQueue(logger, helper, monitorsRepository, workersRepository, scheduler, queueMode);
|
||||||
await instance.init(queueMode);
|
await instance.init(queueMode);
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
@@ -422,8 +425,14 @@ export class LessSimpleQueue implements IJobQueue {
|
|||||||
};
|
};
|
||||||
|
|
||||||
flushQueues = async () => {
|
flushQueues = async () => {
|
||||||
const stopRes = await this.scheduler.stop();
|
if (this.queueMode !== "primary") {
|
||||||
const flushRes = await this.scheduler.flushJobs();
|
// Don't allow workers to flush, though this isn't currently reachable since workers have no API endpoints
|
||||||
|
this.logger.warn({ message: "Ignoring flush on non-primary worker", service: SERVICE_NAME, method: "flushQueues" });
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
|
||||||
|
const flushRes = await this.scheduler.flushJobs(); // Less Simple Queue must flush before stopping as it needs DB
|
||||||
|
const stopRes = await this.scheduler.stop(); // Destructive, other workers will abort their jobs
|
||||||
const initRes = await this.init();
|
const initRes = await this.init();
|
||||||
return {
|
return {
|
||||||
success: Boolean(stopRes && flushRes && initRes),
|
success: Boolean(stopRes && flushRes && initRes),
|
||||||
|
|||||||
Reference in new issue
Block a user