|
|
|
@ -62,6 +62,10 @@ class DummyDocWorkerMap implements IDocWorkerMap {
|
|
|
|
|
this._available = available;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onWorkerUnavailable(workerId: string, cb: () => void) {
|
|
|
|
|
// nothing to do
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async releaseAssignment(workerId: string, docId: string): Promise<void> {
|
|
|
|
|
// nothing to do
|
|
|
|
|
}
|
|
|
|
@ -306,6 +310,28 @@ export class DocWorkerMap implements IDocWorkerMap {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public onWorkerUnavailable(workerId: string, cb: () => void, nbFailures = 0) {
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
|
if (nbFailures >= 3) {
|
|
|
|
|
log.error(
|
|
|
|
|
'DocWorkerMap: Presence checker failed 3 times, considering the worker %d is not available anymore',
|
|
|
|
|
workerId
|
|
|
|
|
);
|
|
|
|
|
return cb();
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
if (!await this._client.sismemberAsync('workers-available', workerId)) {
|
|
|
|
|
log.error("DocWorkerMap: Worker %d has been marked as unavailable in Redis", workerId);
|
|
|
|
|
return cb();
|
|
|
|
|
}
|
|
|
|
|
return this.onWorkerUnavailable(workerId, cb);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
log.error('DocWorkerMap: Presence checker failed', err);
|
|
|
|
|
return this.onWorkerUnavailable(workerId, cb, nbFailures + 1);
|
|
|
|
|
}
|
|
|
|
|
}, 30_000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async releaseAssignment(workerId: string, docId: string): Promise<void> {
|
|
|
|
|
const op = this._client.multi();
|
|
|
|
|
op.del(`doc-${docId}`);
|
|
|
|
|