mirror of
https://github.com/MAGICGrants/campaign-site.git
synced 2026-01-08 20:08:05 -05:00
feat: remove donation migration worker
This commit is contained in:
@@ -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<PerkPurchaseWorkerData>('PerkPurchase', {
|
||||
connection,
|
||||
})
|
||||
export const perkPurchaseQueue = new Queue<PerkPurchaseWorkerData>('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' }
|
||||
)
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user