Skip to content

Commit

Permalink
feat: [PLA-1610] Save only valid metadata properties (#890)
Browse files Browse the repository at this point in the history
fixes
  • Loading branch information
justraman authored Feb 13, 2024
1 parent 6578f53 commit a36ce9a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/job-handlers/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import express from 'express'
import { createBullBoard } from '@bull-board/api'
import { BullAdapter } from '@bull-board/api/bullAdapter'
import { ExpressAdapter } from '@bull-board/express'
import * as Sentry from '@sentry/node'
import connection from '../connection'
import { collectionStatsQueue } from '../jobs/collection-stats'
import { metadataQueue } from '../jobs/process-metadata'
Expand Down Expand Up @@ -32,6 +33,14 @@ async function main() {
fetchCollectionExtraQueue.process(5, `${__dirname}/fetch-collection-extra.js`)
invalidateExpiredListings.process(1, `${__dirname}/invalidate-expired-listings.js`)

traitsQueue.on('global:failed', (job, err) => {
Sentry.captureMessage(`traitsQueue:Job ${job.id} failed with error: ${err.message}`, 'warning')
})

metadataQueue.on('global:failed', (job, err) => {
Sentry.captureMessage(`metadataQueue:Job ${job.id} failed with error: ${err.message}`, 'warning')
})

const serverAdapter = new ExpressAdapter()
serverAdapter.setBasePath('/')

Expand Down
4 changes: 2 additions & 2 deletions src/jobs/collection-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { computeTraits } from './compute-traits'
export type JobData = { collectionId: string }

export const collectionStatsQueue = new Queue<JobData>('collectionStatsQueue', {
defaultJobOptions: { delay: 2000, attempts: 3, removeOnComplete: 500 },
defaultJobOptions: { delay: 1000, attempts: 3, removeOnComplete: true },
redis: redisConfig,
settings: {
maxStalledCount: 3,
Expand All @@ -23,7 +23,7 @@ export const syncCollectionStats = async (collectionId: string) => {
return
}

collectionStatsQueue.add({ collectionId }).catch(() => {
collectionStatsQueue.add({ collectionId }, { jobId: collectionId }).catch(() => {
// eslint-disable-next-line no-console
console.log('Closing connection as Redis is not available')
collectionStatsQueue.close(true)
Expand Down
4 changes: 2 additions & 2 deletions src/jobs/compute-traits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { redisConfig } from './common'
export type JobData = { collectionId: string }

export const traitsQueue = new Queue<JobData>('traitsQueue', {
defaultJobOptions: { delay: 5000, attempts: 3, removeOnComplete: 500 },
defaultJobOptions: { delay: 2000, attempts: 3, removeOnComplete: true },
redis: redisConfig,
settings: {
maxStalledCount: 3,
Expand All @@ -20,7 +20,7 @@ export const computeTraits = async (collectionId: string) => {
return
}

traitsQueue.add({ collectionId }).catch(() => {
traitsQueue.add({ collectionId }, { jobId: collectionId }).catch(() => {
// eslint-disable-next-line no-console
console.log('Closing connection as Redis is not available')
traitsQueue.close(true)
Expand Down
4 changes: 3 additions & 1 deletion src/mappings/util/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ function parseObjectProperties(value: object) {
// eslint-disable-next-line no-restricted-syntax
for (const [k, v] of Object.entries(value)) {
if (typeof v === 'object') {
properties[k] = v
if ('value' in v) {
properties[k] = v
}
} else {
properties[k] = {
value: v,
Expand Down

0 comments on commit a36ce9a

Please sign in to comment.