Skip to content

Commit

Permalink
fix: unexpected error when fetching entities from Catalyst
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega committed Jul 1, 2024
1 parent bbc9740 commit a6072c8
Showing 1 changed file with 51 additions and 39 deletions.
90 changes: 51 additions & 39 deletions src/adapters/deployer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,67 @@ export function createDeployerComponent(
return {
async deployEntity(entity, servers) {
const markAsDeployed = entity.markAsDeployed ? entity.markAsDeployed : async () => {}
if (entity.entityType === 'scene' || entity.entityType === 'wearable' || entity.entityType === 'emote') {
const exists = await components.storage.exist(entity.entityId)
try {
if (entity.entityType === 'scene' || entity.entityType === 'wearable' || entity.entityType === 'emote') {
const exists = await components.storage.exist(entity.entityId)

if (!exists) {
await components.downloadQueue.onSizeLessThan(1000)
if (!exists) {
await components.downloadQueue.onSizeLessThan(1000)

void components.downloadQueue.scheduleJob(async () => {
logger.info('Downloading entity', {
entityId: entity.entityId,
entityType: entity.entityType,
servers: servers.join(',')
})
void components.downloadQueue.scheduleJob(async () => {
logger.info('Downloading entity', {
entityId: entity.entityId,
entityType: entity.entityType,
servers: servers.join(',')
})

await downloadEntityAndContentFiles(
{ ...components, fetcher: components.fetch },
entity.entityId,
servers,
new Map(),
'content',
10,
1000
)
await downloadEntityAndContentFiles(
{ ...components, fetcher: components.fetch },
entity.entityId,
servers,
new Map(),
'content',
10,
1000
)

logger.info('Entity stored', { entityId: entity.entityId, entityType: entity.entityType })
logger.info('Entity stored', { entityId: entity.entityId, entityType: entity.entityType })

// send sns
if (components.sns.arn) {
const deploymentToSqs: DeploymentToSqs = {
entity,
contentServerUrls: servers
}
const receipt = await sns
.publish({
TopicArn: components.sns.arn,
Message: JSON.stringify(deploymentToSqs)
// send sns
if (components.sns.arn) {
const deploymentToSqs: DeploymentToSqs = {
entity,
contentServerUrls: servers
}
const receipt = await sns
.publish({
TopicArn: components.sns.arn,
Message: JSON.stringify(deploymentToSqs)
})
.promise()
logger.info('Notification sent', {
MessageId: receipt.MessageId as any,
SequenceNumber: receipt.SequenceNumber as any
})
.promise()
logger.info('Notification sent', {
MessageId: receipt.MessageId as any,
SequenceNumber: receipt.SequenceNumber as any
})
}
}
await markAsDeployed()
})
} else {
await markAsDeployed()
})
}
} else {
await markAsDeployed()
}
} else {
await markAsDeployed()
} catch (error: any) {
const isNotRetryable = /status: 4\d{2}/.test(error.message)
if (isNotRetryable) {
logger.error('Failed to download entity', {
entityId: entity.entityId,
entityType: entity.entityType,
error: error?.message
})
await markAsDeployed()
}
}
},
async onIdle() {}
Expand Down

0 comments on commit a6072c8

Please sign in to comment.