fix errors for discogs and use env settings in mcrates compose

This commit is contained in:
ntr committed 2023-02-08 23:05:23 +11:00
1 parent 2ffb5f9bc3
commit ac0a31511d
4 files changed
+17 -9

No files matched your search

+3 -3
View File
@@ -42,7 +42,6 @@ export default function createDiscogs(log: Log, pg: Pg) {
}
function onError(error) {
console.error(error);
if (error.response.status === 429) {
return [new Error('rate limited, try again in 1 minute'), null];
}
@@ -54,7 +53,6 @@ export default function createDiscogs(log: Log, pg: Pg) {
async function wantListSync(username: string, user: User): Promise<Want[]> {
const [err, res] = await api.get(`${apiBase}/users/${username}/wants`);
log.warn(err, res);
if (err) throw err;
const { wants, pagination } = res;
@@ -75,7 +73,8 @@ export default function createDiscogs(log: Log, pg: Pg) {
}
async function release(id: DiscogsRelease): Promise<any> {
const [error, data] = await api.get(`${apiBase}/releases/${id}`);
const [err, data] = await api.get(`${apiBase}/releases/${id}`);
if (err) throw err;
return data;
}
@@ -121,6 +120,7 @@ export default function createDiscogs(log: Log, pg: Pg) {
log.debug('fetching listing', id);
const [err, discogsListing] = await api.get(`${apiBase}/marketplace/listings/${id}`);
if (err) throw err;
log.debug(discogsListing);
return pg.listingUpsert(discogsListing, want);
}
+6 -2
View File
@@ -27,7 +27,8 @@ export default function createEvents(log: Log, pg: Pg, discogs, offers) {
log.error('event error', e);
});
async function populateListings(want: Want) {
const MAX_ATTEMPTS = 2;
async function populateListings(want: Want, attempts = 0) {
try {
const listings = await discogs.listings(want);
await pg.wantSynced(want);
@@ -36,7 +37,10 @@ export default function createEvents(log: Log, pg: Pg, discogs, offers) {
if (e.message.includes('rate limited')) {
log.warn('rate limited, trying again in 60s');
await setTimeout(60 * 1000);
return populateListings(want);
if (attempts > MAX_ATTEMPTS) {
log.error(wantDetails(want), 'failed to populate listings')
}
return populateListings(want, attempts++);
}
throw e;
}
+4
View File
@@ -51,6 +51,8 @@ body {
.info {
display: grid;
overflow: hidden;
grid-template-areas:
"words swirl"
"words contact";
@@ -65,10 +67,12 @@ body {
.contact {
grid-area: contact;
text-align: center;
overflow: scroll;
}
.words {
grid-area: words;
overflow: scroll;
}
.swirl {
+4 -4
View File
@@ -4,9 +4,9 @@ services:
pg:
image: postgres:latest
environment:
POSTGRES_USER: 'mcrates'
POSTGRES_DB: 'mcrates'
POSTGRES_PASSWORD: 'digdeep'
POSTGRES_USER: '${POSTGRES_USER}'
POSTGRES_DB: '${POSTGRES_DB}'
POSTGRES_PASSWORD: '${POSTGRES_PASSWORD}'
# allow prisma client to push changes from outside docker etc
# ufw blocks this from being publicly accessible
@@ -20,7 +20,7 @@ services:
working_dir: /opt/mcrates/api
entrypoint: npm start
environment:
DATABASE_URL: 'postgresql://mcrates:digdeep@pg:5432/mcrates?schema=public'
DATABASE_URL: 'postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@pg:5432/${POSTGRES_DB}?schema=public'
volumes:
- "./api:/opt/mcrates/api"