sync constantly
This commit is contained in:
1 parent
c6bf50f963
commit
36fc3665dd
5 files changed
+37
-16
No files matched your search
+17
-3
@@ -5,6 +5,7 @@ import * as Bluebird from 'bluebird';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { Status } from './offers';
|
||||
import { wantDetails } from './utils';
|
||||
|
||||
export interface UserCreateParams {
|
||||
email: string,
|
||||
@@ -112,7 +113,12 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
||||
}
|
||||
|
||||
async function wantsToSync() {
|
||||
return prisma.want.findMany({});
|
||||
return prisma.want.findMany({
|
||||
orderBy: { updatedAt: 'asc' },
|
||||
where: {
|
||||
updatedAt: { lte: new Date(Date.now() - 1000 * 60 * 15) }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function wantRm(id: UUID) {
|
||||
@@ -133,6 +139,13 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
||||
});
|
||||
}
|
||||
|
||||
async function wantSynced(want: Want) {
|
||||
return prisma.want.update({
|
||||
where: { id: want.id },
|
||||
data: { updatedAt: new Date() },
|
||||
});
|
||||
}
|
||||
|
||||
async function listingRmUnlisted(want: Want, currentListingIds: DiscogsListing[]) {
|
||||
return prisma.$transaction(async (prisma) => {
|
||||
log.debug({ currentListingIds });
|
||||
@@ -153,7 +166,7 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
||||
}
|
||||
});
|
||||
|
||||
if (offersRemoved > 0) log.info({ offersRemoved }, 'pending offers removed');
|
||||
if (offersRemoved > 0) log.info({ offersRemoved, ...wantDetails(want) }, 'pending offers removed');
|
||||
|
||||
// now we have to filter listingIds with confirmed offers
|
||||
// and get their listingIds to filter out
|
||||
@@ -180,7 +193,7 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
||||
},
|
||||
});
|
||||
|
||||
log.info({ count }, 'second stage open offers removed');
|
||||
if (count) log.info({ count }, 'second stage open offers removed');
|
||||
|
||||
return count;
|
||||
});
|
||||
@@ -305,6 +318,7 @@ export default function createPg(log: Log, prisma: PrismaClient) {
|
||||
wantCreate,
|
||||
wantList,
|
||||
wantsToSync,
|
||||
wantSynced,
|
||||
wantRm,
|
||||
|
||||
listingUpsert,
|
||||
|
||||
Reference in new issue
Block a user