diff --git a/server/queues.ts b/server/queues.ts index 5608d09..bce1c10 100644 --- a/server/queues.ts +++ b/server/queues.ts @@ -4,24 +4,13 @@ import { redisConnection as connection } from '../config/redis' import './workers/perk' import './workers/membership-check' -import './workers/donation-migration' -export const perkPurchaseQueue = new Queue('PerkPurchase', { - connection, -}) +export const perkPurchaseQueue = new Queue('PerkPurchase', { connection }) export const membershipCheckQueue = new Queue('MembershipCheck', { connection }) -export const donationMigration = new Queue('DonationMigration', { connection }) - membershipCheckQueue.upsertJobScheduler( 'MembershipCheckScheduler', { pattern: '0 * * * *' }, { name: 'MembershipCheck' } ) - -donationMigration.upsertJobScheduler( - 'DonationMigrationScheduler', - { pattern: '* * * * *' }, - { name: 'DonationMigration' } -) diff --git a/server/workers/donation-migration.ts b/server/workers/donation-migration.ts deleted file mode 100644 index 7d4c33b..0000000 --- a/server/workers/donation-migration.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { Worker } from 'bullmq' -import { redisConnection as connection } from '../../config/redis' -import { prisma } from '../services' -import { DonationCryptoPayments } from '../types' -import { log } from '../../utils/logging' -import { Prisma } from '@prisma/client' - -const globalForWorker = global as unknown as { hasInitializedWorkers: boolean } - -if (!globalForWorker.hasInitializedWorkers) - new Worker( - 'DonationMigration', - async (job) => { - // Finds unmigrated donations and updates them - log('info', '[Donation migration] Migrating old donations...') - - const donations = await prisma.donation.findMany({ - where: { - btcPayInvoiceId: { not: null }, - cryptoPayments: { equals: Prisma.DbNull }, - }, - }) - - if (!donations.length) return - - await Promise.all( - donations.map(async (donation) => { - const cryptoPayments: DonationCryptoPayments = [ - { - cryptoCode: donation.cryptoCode as DonationCryptoPayments[0]['cryptoCode'], - grossAmount: Number(donation.grossCryptoAmount!), - netAmount: Number(donation.netCryptoAmount), - rate: donation.grossFiatAmount / Number(donation.grossCryptoAmount), - }, - ] - - await prisma.donation.update({ - where: { id: donation.id }, - data: { - cryptoPayments, - cryptoCode: null, - grossCryptoAmount: null, - netCryptoAmount: null, - }, - }) - }) - ) - - log('info', `[Donation migration] Successfully updated ${donations.length} records!!!!!!!!!!`) - }, - { connection } - ) - -if (process.env.NODE_ENV !== 'production') globalForWorker.hasInitializedWorkers = true