External storage: split checkBackend and configure (follow-up #545) (#567)

This fixes an issue with external storage in saas environment.

See https://github.com/gristlabs/grist-core/pull/546/files#r1259340397

Co-authored-by: Florent FAYOLLE <florent.fayolle@beta.gouv.fr>
This commit is contained in:
Florent 2023-07-13 08:44:46 +02:00 committed by GitHub
parent b0f76a152f
commit 7694588a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -1132,9 +1132,6 @@ export class FlexServer implements GristServer {
await this.loadConfig();
this.addComm();
// Temporary duplication of external storage configuration.
// This may break https://github.com/gristlabs/grist-core/pull/546,
// but will revive other uses of external storage. TODO: reconcile.
await this.create.configure?.();
if (!isSingleUserMode()) {
@ -1147,7 +1144,7 @@ export class FlexServer implements GristServer {
this._disableExternalStorage = true;
externalStorage.flag('active').set(false);
}
await this.create.configure?.();
await this.create.checkBackend?.();
const workers = this._docWorkerMap;
const docWorkerId = await this._addSelfAsWorker(workers);

View File

@ -32,6 +32,8 @@ export interface ICreate {
sessionSecret(): string;
// Check configuration of the app early enough to show on startup.
configure?(): Promise<void>;
// Optionally perform sanity checks on the configured storage, throwing a fatal error if it is not functional
checkBackend?(): Promise<void>;
// Return a string containing 1 or more HTML tags to insert into the head element of every
// static page.
getExtraHeadHtml?(): string;
@ -119,6 +121,13 @@ export function makeSimpleCreator(opts: {
return secret;
},
async configure() {
for (const s of storage || []) {
if (s.check()) {
break;
}
}
},
async checkBackend() {
for (const s of storage || []) {
if (s.check()) {
await s.checkBackend?.();