From b6b169e6dfa2f78d63694a826a207522c82ed454 Mon Sep 17 00:00:00 2001 From: Braian Mellor Date: Wed, 18 Sep 2024 15:21:12 -0300 Subject: [PATCH] fix: service falling down (#499) * fix: service falling down --- src/adapters/deployer/index.ts | 108 +++++++++++++++++---------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/src/adapters/deployer/index.ts b/src/adapters/deployer/index.ts index 3dc454b..ec3d81f 100644 --- a/src/adapters/deployer/index.ts +++ b/src/adapters/deployer/index.ts @@ -19,66 +19,70 @@ export function createDeployerComponent( try { const exists = await components.storage.exist(entity.entityId) - if (!exists) { - await components.downloadQueue.onSizeLessThan(1000) + const isSnsEntityToSend = + (entity.entityType === 'scene' || entity.entityType === 'wearable' || entity.entityType === 'emote') && + !!components.sns.arn - void components.downloadQueue.scheduleJob(async () => { - logger.info('Downloading entity', { - entityId: entity.entityId, - entityType: entity.entityType, - servers: servers.join(',') - }) + const isSnsEventToSend = !!components.sns.eventArn - await downloadEntityAndContentFiles( - { ...components, fetcher: components.fetch }, - entity.entityId, - servers, - new Map(), - 'content', - 10, - 1000 - ) + if (exists || !(isSnsEntityToSend && isSnsEventToSend)) { + return await markAsDeployed() + } + + await components.downloadQueue.onSizeLessThan(1000) + + void components.downloadQueue.scheduleJob(async () => { + logger.info('Downloading entity', { + entityId: entity.entityId, + entityType: entity.entityType, + servers: servers.join(',') + }) - logger.info('Entity stored', { entityId: entity.entityId, entityType: entity.entityType }) + await downloadEntityAndContentFiles( + { ...components, fetcher: components.fetch }, + entity.entityId, + servers, + new Map(), + 'content', + 10, + 1000 + ) - const deploymentToSqs: DeploymentToSqs = { - entity, - contentServerUrls: servers - } - // send sns - if ( - (entity.entityType === 'scene' || entity.entityType === 'wearable' || entity.entityType === 'emote') && - components.sns.arn - ) { - const receipt = await client.send( - new PublishCommand({ - TopicArn: components.sns.arn, - Message: JSON.stringify(deploymentToSqs) - }) - ) - logger.info('Notification sent', { - MessageId: receipt.MessageId as any, - SequenceNumber: receipt.SequenceNumber as any + logger.info('Entity stored', { entityId: entity.entityId, entityType: entity.entityType }) + + const deploymentToSqs: DeploymentToSqs = { + entity, + contentServerUrls: servers + } + + // send sns + if (isSnsEntityToSend) { + const receipt = await client.send( + new PublishCommand({ + TopicArn: components.sns.arn, + Message: JSON.stringify(deploymentToSqs) }) - } + ) + logger.info('Notification sent', { + MessageId: receipt.MessageId as any, + SequenceNumber: receipt.SequenceNumber as any + }) + } - if (components.sns.eventArn) { - const receipt = await client.send( - new PublishCommand({ - TopicArn: components.sns.eventArn, - Message: JSON.stringify(deploymentToSqs) - }) - ) - logger.info('Notification sent to events SNS', { - MessageId: receipt.MessageId as any, - SequenceNumber: receipt.SequenceNumber as any + if (isSnsEventToSend) { + const receipt = await client.send( + new PublishCommand({ + TopicArn: components.sns.eventArn, + Message: JSON.stringify(deploymentToSqs) }) - } - await markAsDeployed() - }) - } else { + ) + logger.info('Notification sent to events SNS', { + MessageId: receipt.MessageId as any, + SequenceNumber: receipt.SequenceNumber as any + }) + } await markAsDeployed() - } + }) } catch (error: any) { const isNotRetryable = /status: 4\d{2}/.test(error.message) if (isNotRetryable) {