moar logs
This commit is contained in:
1 parent
70cb07ee27
commit
44c83d3b33
9 files changed
+113
-22
No files matched your search
+15
-11
@@ -1,9 +1,11 @@
|
||||
import { EventEmitter } from 'node:events';
|
||||
import { setTimeout } from 'timers/promises';
|
||||
|
||||
import type Log from 'bunyan';
|
||||
import type { Want } from '@prisma/client';
|
||||
|
||||
import { Pg } from './pg';
|
||||
import { wantDetails } from './utils';
|
||||
import routerAuth from './routers/router.auth';
|
||||
|
||||
export enum Events {
|
||||
@@ -19,9 +21,10 @@ export default function createEvents(log: Log, pg: Pg, discogs) {
|
||||
});
|
||||
|
||||
events.on(Events.WantsAdded, async function wantsAdded(wants: Want[]) {
|
||||
log.info({ event: Events.WantsAdded, wants: wants.length });
|
||||
for (const want of wants) {
|
||||
const listings = await discogs.listings(want);
|
||||
log.info({ count: listings.length, title: want.id }, 'listings added')
|
||||
log.info({ count: listings.length, ...wantDetails(want) }, 'listings added')
|
||||
}
|
||||
|
||||
log.info('finished fetching listings', { wants: wants.length });
|
||||
@@ -29,20 +32,21 @@ export default function createEvents(log: Log, pg: Pg, discogs) {
|
||||
|
||||
events.on(Events.StartupSync, async function wantsAdded() {
|
||||
const wants = await pg.wantsToSync();
|
||||
log.info({ event: Events.StartupSync, wants: wants.length });
|
||||
|
||||
try {
|
||||
for (const want of wants) {
|
||||
for (const want of wants) {
|
||||
try {
|
||||
const listings = await discogs.listings(want);
|
||||
log.info({ count: listings.length, title: want.id }, 'listings added')
|
||||
}
|
||||
|
||||
log.info('finished syncing', { wants: wants.length });
|
||||
} catch (e) {
|
||||
if (e.message === 'rate limited') {
|
||||
log.warn('rate limited, trying again in 60s');
|
||||
return setTimeout(() => events.emit(Events.StartupSync), 60 * 1000);
|
||||
log.info({ count: listings.length, ...wantDetails(want) }, 'listings added')
|
||||
} catch (e) {
|
||||
if (e.message === 'rate limited') {
|
||||
log.warn('rate limited, trying again in 60s');
|
||||
await setTimeout(60 * 1000);
|
||||
const listings = await discogs.listings(want);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info('finished syncing', { wants: wants.length });
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user