Revert postgres try/catch block
This commit is contained in:
parent
2e16aba098
commit
5d2e598b29
@ -12,7 +12,7 @@ import { parameterize } from '@/utility/string';
|
|||||||
import { Tags } from '@/tag';
|
import { Tags } from '@/tag';
|
||||||
import { FilmSimulation, FilmSimulations } from '@/simulation';
|
import { FilmSimulation, FilmSimulations } from '@/simulation';
|
||||||
import { PRIORITY_ORDER_ENABLED } from '@/site/config';
|
import { PRIORITY_ORDER_ENABLED } from '@/site/config';
|
||||||
// import { screenForPPR } from '@/utility/ppr';
|
import { screenForPPR } from '@/utility/ppr';
|
||||||
|
|
||||||
const PHOTO_DEFAULT_LIMIT = 100;
|
const PHOTO_DEFAULT_LIMIT = 100;
|
||||||
|
|
||||||
@ -20,36 +20,36 @@ export const convertArrayToPostgresString = (array?: string[]) => array
|
|||||||
? `{${array.join(',')}}`
|
? `{${array.join(',')}}`
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
// const sqlCreatePhotosTable = () =>
|
const sqlCreatePhotosTable = () =>
|
||||||
// sql`
|
sql`
|
||||||
// CREATE TABLE IF NOT EXISTS photos (
|
CREATE TABLE IF NOT EXISTS photos (
|
||||||
// id VARCHAR(8) PRIMARY KEY,
|
id VARCHAR(8) PRIMARY KEY,
|
||||||
// url VARCHAR(255) NOT NULL,
|
url VARCHAR(255) NOT NULL,
|
||||||
// extension VARCHAR(255) NOT NULL,
|
extension VARCHAR(255) NOT NULL,
|
||||||
// aspect_ratio REAL DEFAULT 1.5,
|
aspect_ratio REAL DEFAULT 1.5,
|
||||||
// blur_data TEXT,
|
blur_data TEXT,
|
||||||
// title VARCHAR(255),
|
title VARCHAR(255),
|
||||||
// tags VARCHAR(255)[],
|
tags VARCHAR(255)[],
|
||||||
// make VARCHAR(255),
|
make VARCHAR(255),
|
||||||
// model VARCHAR(255),
|
model VARCHAR(255),
|
||||||
// focal_length SMALLINT,
|
focal_length SMALLINT,
|
||||||
// focal_length_in_35mm_format SMALLINT,
|
focal_length_in_35mm_format SMALLINT,
|
||||||
// f_number REAL,
|
f_number REAL,
|
||||||
// iso SMALLINT,
|
iso SMALLINT,
|
||||||
// exposure_time DOUBLE PRECISION,
|
exposure_time DOUBLE PRECISION,
|
||||||
// exposure_compensation REAL,
|
exposure_compensation REAL,
|
||||||
// location_name VARCHAR(255),
|
location_name VARCHAR(255),
|
||||||
// latitude DOUBLE PRECISION,
|
latitude DOUBLE PRECISION,
|
||||||
// longitude DOUBLE PRECISION,
|
longitude DOUBLE PRECISION,
|
||||||
// film_simulation VARCHAR(255),
|
film_simulation VARCHAR(255),
|
||||||
// priority_order REAL,
|
priority_order REAL,
|
||||||
// taken_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
taken_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||||
// taken_at_naive VARCHAR(255) NOT NULL,
|
taken_at_naive VARCHAR(255) NOT NULL,
|
||||||
// hidden BOOLEAN,
|
hidden BOOLEAN,
|
||||||
// updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
|
||||||
// created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
|
||||||
// )
|
)
|
||||||
// `;
|
`;
|
||||||
|
|
||||||
// Must provide id as 8-character nanoid
|
// Must provide id as 8-character nanoid
|
||||||
export const sqlInsertPhoto = (photo: PhotoDbInsert) => {
|
export const sqlInsertPhoto = (photo: PhotoDbInsert) => {
|
||||||
@ -291,30 +291,29 @@ const safelyQueryPhotos = async <T>(callback: () => Promise<T>): Promise<T> => {
|
|||||||
|
|
||||||
result = await callback();
|
result = await callback();
|
||||||
|
|
||||||
// try {
|
try {
|
||||||
// result = await callback();
|
result = await callback();
|
||||||
// } catch (e: any) {
|
} catch (e: any) {
|
||||||
// screenForPPR(e, undefined, 'neon postgres');
|
screenForPPR(e, undefined, 'neon postgres');
|
||||||
// if (/relation "photos" does not exist/i.test(e.message)) {
|
if (/relation "photos" does not exist/i.test(e.message)) {
|
||||||
// console.log('Creating table "photos" because it did not exist');
|
console.log('Creating table "photos" because it did not exist');
|
||||||
// await sqlCreatePhotosTable();
|
await sqlCreatePhotosTable();
|
||||||
// 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)) {
|
||||||
// eslint-disable-next-line max-len
|
console.log('sql get error: endpoint is in transition (setting timeout)');
|
||||||
// console.log('sql get 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 get error on retry (after 5000ms): ${e.message} `);
|
throw e;
|
||||||
// throw e;
|
}
|
||||||
// }
|
} else {
|
||||||
// } else {
|
console.log(`sql get error: ${e.message} `);
|
||||||
// console.log(`sql get error: ${e.message} `);
|
throw e;
|
||||||
// throw e;
|
}
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user