(core) Add unquarantine command to admin CLI

Summary:
Adds a CLI command to un-quarantine an active document. Also tweaks the
name of related environment variable to avoid a naming conflict.

Test Plan: Server test.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3583
This commit is contained in:
George Gevoian 2022-08-15 12:52:38 -07:00
parent 103c795aa2
commit 0c5441b176
4 changed files with 23 additions and 6 deletions

View File

@ -141,6 +141,10 @@ class DummyDocWorkerMap implements IDocWorkerMap {
// nothing to do
}
public async removeDocGroup(docId: string): Promise<void> {
// nothing to do
}
public getRedisClient() {
return null;
}
@ -525,6 +529,10 @@ export class DocWorkerMap implements IDocWorkerMap {
await this._client.setAsync(`doc-${docId}-group`, docGroup);
}
public async removeDocGroup(docId: string): Promise<void> {
await this._client.delAsync(`doc-${docId}-group`);
}
public getRedisClient(): RedisClient {
return this._client;
}

View File

@ -166,12 +166,12 @@ export class Housekeeper {
// actions.
//
// Optionally accepts a `group` query param for updating the document's group prior
// to moving. This is useful for controlling which worker group the document is assigned
// a worker from.
// to moving. A blank string unsets the current group, if any. This is useful for controlling
// which worker group the document is assigned a worker from.
app.post('/api/housekeeping/docs/:docId/assign', this._withSupport(async (req, docId, headers) => {
const url = new URL(await this._server.getHomeUrlByDocId(docId, `/api/docs/${docId}/assign`));
const group = optStringParam(req.query.group);
if (group) { url.searchParams.set('group', group); }
if (group !== undefined) { url.searchParams.set('group', group); }
return fetch(url.toString(), {
method: 'POST',
headers,

View File

@ -601,13 +601,18 @@ export class DocWorkerApi {
// is freed up for reassignment, otherwise false.
//
// Optionally accepts a `group` query param for updating the document's group prior
// to (possible) reassignment. (Note: Requires special permit.)
// to (possible) reassignment. A blank string unsets the current group, if any.
// (Requires a special permit.)
this._app.post('/api/docs/:docId/assign', canEdit, throttled(async (req, res) => {
const docId = getDocId(req);
const group = optStringParam(req.query.group);
if (group && req.specialPermit?.action === 'assign-doc') {
if (group !== undefined && req.specialPermit?.action === 'assign-doc') {
if (group.trim() === '') {
await this._docWorkerMap.removeDocGroup(docId);
} else {
await this._docWorkerMap.updateDocGroup(docId, group);
}
}
const status = await this._docWorkerMap.getDocWorker(docId);
if (!status) { res.json(false); return; }
const workerGroup = await this._docWorkerMap.getWorkerGroup(status.docWorker.id);

View File

@ -66,8 +66,12 @@ export interface IDocWorkerMap extends IPermitStores, IElectionStore, IChecksumS
getAssignments(workerId: string): Promise<string[]>;
getWorkerGroup(workerId: string): Promise<string|null>;
getDocGroup(docId: string): Promise<string|null>;
updateDocGroup(docId: string, docGroup: string): Promise<void>;
removeDocGroup(docId: string): Promise<void>;
getRedisClient(): RedisClient|null;
}