Skip to content

Commit

Permalink
feat: Improve metadata job (#1035)
Browse files Browse the repository at this point in the history
improve metadta job
  • Loading branch information
justraman authored Apr 27, 2024
1 parent b252241 commit f7dd193
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 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: 2000, attempts: 2, removeOnComplete: true },
defaultJobOptions: { delay: 3000, attempts: 2, removeOnComplete: true },
redis: redisConfig,
settings: {
maxStalledCount: 3,
Expand Down
10 changes: 9 additions & 1 deletion src/jobs/process-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import { redisConfig } from './common'
export type JobData = { resourceId: string; type: 'token' | 'collection'; force: boolean; allTokens: boolean }

export const metadataQueue = new Queue<JobData>('metadataQueue', {
defaultJobOptions: { delay: 1000, attempts: 1, removeOnComplete: true },
defaultJobOptions: {
delay: 100,
attempts: 3,
backoff: {
type: 'exponential',
delay: 3000,
},
removeOnComplete: true,
},
redis: redisConfig,
settings: {
maxStalledCount: 2,
Expand Down
9 changes: 8 additions & 1 deletion src/mappings/util/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ export async function fetchMetadata(url: string, job: Queue.Job) {
maxRedirects: url.startsWith('https://platform.production.enjinusercontent.com/') ? 3 : 1,
httpsAgent: new https.Agent({ keepAlive: true, rejectUnauthorized: false }),
})

let finalUrl = url.replace('ipfs://', 'https://ipfs.io/ipfs/')
if (job.attemptsMade > 1) {
finalUrl = url.replace('ipfs://', 'https://cloudflare-ipfs.com/ipfs/')
job.log(`Fetching metadata from ${finalUrl} attempt ${job.attemptsMade}`)
}

try {
const { status, data } = await api.get(url.replace('ipfs://', 'https://ipfs.io/ipfs/'))
const { status, data } = await api.get(finalUrl)
if (status < 400) {
return data
}
Expand Down

0 comments on commit f7dd193

Please sign in to comment.