• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

decentraland / deployments-to-sqs / 12161275714

04 Dec 2024 01:58PM UTC coverage: 49.664% (-2.5%) from 52.143%
12161275714

push

github

web-flow
chore: handle falsy on optional SNS endpoint (#513)

2 of 28 branches covered (7.14%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

72 of 121 relevant lines covered (59.5%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

12.7
/src/adapters/deployer/index.ts
1
import { downloadEntityAndContentFiles } from '@dcl/snapshots-fetcher'
1✔
2
import { IDeployerComponent } from '@dcl/snapshots-fetcher/dist/types'
3
import { PublishCommand, SNSClient } from '@aws-sdk/client-sns'
1✔
4
import { AppComponents } from '../../types'
5
import { DeploymentToSqs } from '@dcl/schemas/dist/misc/deployments-to-sqs'
6
import { Events } from '@dcl/schemas/dist/platform/events'
1✔
7

8
export function createDeployerComponent(
1✔
9
  components: Pick<AppComponents, 'logs' | 'storage' | 'downloadQueue' | 'fetch' | 'metrics' | 'sns'>
10
): IDeployerComponent {
11
  const logger = components.logs.getLogger('downloader')
1✔
12

13
  const client = new SNSClient({
1✔
14
    endpoint: components.sns.optionalSnsEndpoint ? components.sns.optionalSnsEndpoint : undefined
1!
15
  })
16

17
  return {
1✔
18
    async deployEntity(entity, servers) {
19
      const markAsDeployed = entity.markAsDeployed ? entity.markAsDeployed : async () => {}
×
20
      try {
×
21
        const exists = await components.storage.exist(entity.entityId)
×
22

23
        const isSnsEntityToSend =
24
          (entity.entityType === 'scene' || entity.entityType === 'wearable' || entity.entityType === 'emote') &&
×
25
          !!components.sns.arn
26

27
        const isSnsEventToSend = !!components.sns.eventArn
×
28

NEW
29
        logger.debug('Handling entity', {
×
30
          entityId: entity.entityId,
31
          entityType: entity.entityType,
32
          exists: exists ? 'true' : 'false',
×
33
          isSnsEntityToSend: isSnsEntityToSend ? 'true' : 'false',
×
34
          isSnsEventToSend: isSnsEventToSend ? 'true' : 'false'
×
35
        })
36

37
        if (exists || !(isSnsEntityToSend && isSnsEventToSend)) {
×
38
          return await markAsDeployed()
×
39
        }
40

41
        await components.downloadQueue.onSizeLessThan(1000)
×
42

43
        void components.downloadQueue.scheduleJob(async () => {
×
44
          logger.info('Downloading entity', {
×
45
            entityId: entity.entityId,
46
            entityType: entity.entityType,
47
            servers: servers.join(',')
48
          })
49

50
          try {
×
51
            await downloadEntityAndContentFiles(
×
52
              { ...components, fetcher: components.fetch },
53
              entity.entityId,
54
              servers,
55
              new Map(),
56
              'content',
57
              10,
58
              1000
59
            )
60
          } catch (error: any) {
61
            logger.error('Failed to download entity', {
×
62
              entityId: entity.entityId,
63
              entityType: entity.entityType,
64
              errorMessage: error.message
65
            })
66

67
            const match = error.message?.match(/status: 4\d{2}/)
×
68

69
            if (match) {
×
70
              await markAsDeployed()
×
71
            }
72

73
            return
×
74
          }
75

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

78
          const deploymentToSqs: DeploymentToSqs = {
×
79
            entity,
80
            contentServerUrls: servers
81
          }
82

83
          // send sns
84
          if (isSnsEntityToSend) {
×
85
            const receipt = await client.send(
×
86
              new PublishCommand({
87
                TopicArn: components.sns.arn,
88
                Message: JSON.stringify(deploymentToSqs)
89
              })
90
            )
91
            logger.info('Notification sent', {
×
92
              messageId: receipt.MessageId as any,
93
              sequenceNumber: receipt.SequenceNumber as any,
94
              entityId: entity.entityId,
95
              entityType: entity.entityType
96
            })
97
          }
98

99
          if (isSnsEventToSend) {
×
100
            // TODO: this should be a CatalystDeploymentEvent
101
            const deploymentEvent = {
×
102
              type: Events.Type.CATALYST_DEPLOYMENT,
103
              subType: entity.entityType as Events.SubType.CatalystDeployment,
104
              ...deploymentToSqs
105
            } as any
106

107
            const receipt = await client.send(
×
108
              new PublishCommand({
109
                TopicArn: components.sns.eventArn,
110
                Message: JSON.stringify(deploymentEvent),
111
                MessageAttributes: {
112
                  type: { DataType: 'String', StringValue: deploymentEvent.type },
113
                  subType: { DataType: 'String', StringValue: deploymentEvent.subType }
114
                }
115
              })
116
            )
117
            logger.info('Notification sent to events SNS', {
×
118
              MessageId: receipt.MessageId as any,
119
              SequenceNumber: receipt.SequenceNumber as any,
120
              entityId: entity.entityId,
121
              entityType: entity.entityType
122
            })
123
          }
124
          await markAsDeployed()
×
125
        })
126
      } catch (error: any) {
127
        const isNotRetryable = /status: 4\d{2}/.test(error.message)
×
128
        logger.error('Failed to publish entity', {
×
129
          entityId: entity.entityId,
130
          entityType: entity.entityType,
131
          error: error?.message,
132
          stack: error?.stack
133
        })
134

135
        if (isNotRetryable) {
×
136
          logger.error('Failed to download entity', {
×
137
            entityId: entity.entityId,
138
            entityType: entity.entityType,
139
            error: error?.message
140
          })
141
          await markAsDeployed()
×
142
        }
143
      }
144
    },
145
    async onIdle() {}
146
  }
147
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc