Augment sql logging
This commit is contained in:
parent
ef62781a40
commit
3152c4f2aa
@ -14,7 +14,7 @@ type StaticOutput = 'page' | 'image';
|
|||||||
|
|
||||||
const logStaticGenerationDetails = (count: number, content: string) => {
|
const logStaticGenerationDetails = (count: number, content: string) => {
|
||||||
const label = pluralize(count, content, undefined, 3);
|
const label = pluralize(count, content, undefined, 3);
|
||||||
console.log(`Statically generating ${label} ...`);
|
console.log(`> Statically generating ${label} ...`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const staticallyGeneratePhotosIfConfigured = (type: StaticOutput) =>
|
export const staticallyGeneratePhotosIfConfigured = (type: StaticOutput) =>
|
||||||
|
|||||||
@ -65,8 +65,8 @@ const createPhotosTable = () =>
|
|||||||
)
|
)
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Safe wrapper for most queries with JIT table creation/migration
|
// Safe wrapper intended for most queries with JIT migration/table creation
|
||||||
// Catch up to 3 migrations in older installations
|
// Catches up to 3 migrations in older installations
|
||||||
const safelyQueryPhotos = async <T>(
|
const safelyQueryPhotos = async <T>(
|
||||||
callback: () => Promise<T>,
|
callback: () => Promise<T>,
|
||||||
queryLabel: string,
|
queryLabel: string,
|
||||||
@ -115,19 +115,25 @@ const safelyQueryPhotos = async <T>(
|
|||||||
await createPhotosTable();
|
await createPhotosTable();
|
||||||
result = await callback();
|
result = await callback();
|
||||||
} else if (/endpoint is in transition/i.test(e.message)) {
|
} else if (/endpoint is in transition/i.test(e.message)) {
|
||||||
console.log('sql get error: endpoint is in transition (setting timeout)');
|
console.log(
|
||||||
|
'SQL query error: endpoint is in transition (setting timeout)',
|
||||||
|
);
|
||||||
// Wait 5 seconds and try again
|
// Wait 5 seconds and try again
|
||||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||||
try {
|
try {
|
||||||
result = await callback();
|
result = await callback();
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.log(`sql get error on retry (after 5000ms): ${e.message}`);
|
console.log(
|
||||||
|
`SQL query error on retry (after 5000ms): ${e.message}`,
|
||||||
|
);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Avoid re-logging errors on initial installation
|
||||||
if (e.message !== 'The server does not support SSL connections') {
|
if (e.message !== 'The server does not support SSL connections') {
|
||||||
// Avoid re-logging errors on initial installation
|
console.log(`SQL query error (${queryLabel}): ${e.message}`, {
|
||||||
console.log(`sql get error (${queryLabel}): ${e.message}`);
|
error: e,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user