Skip to content

Commit

Permalink
feat: publish AssetBundleConverted event
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega committed Dec 4, 2024
1 parent d6fa698 commit 763e528
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
3 changes: 3 additions & 0 deletions consumer-server/.env.default
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ HTTP_SERVER_HOST=0.0.0.0
# reset metrics at 00:00UTC
WKC_METRICS_RESET_AT_NIGHT=false


ENV=prd
SENTRY_DSN=

AWS_SNS_ARN=any
2 changes: 1 addition & 1 deletion consumer-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"@aws-sdk/client-sns": "^3.699.0",
"@dcl/cdn-uploader": "^1.4.1-20230208155013.commit-f75a6ee",
"@dcl/schemas": "https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/asset-bundle-events/dcl-schemas-15.1.3-12164880486.commit-e79c069.tgz",
"@dcl/schemas": "^15.2.0",
"@sentry/node": "^8.27.0",
"@well-known-components/env-config-provider": "^1.2.0",
"@well-known-components/http-server": "^2.1.0",
Expand Down
38 changes: 18 additions & 20 deletions consumer-server/src/adapters/sns.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
import { PublishCommand, SNSClient } from '@aws-sdk/client-sns'
import { AppComponents, PublisherComponent } from '../types'

export async function createSnsComponent({
config,
}: Pick<AppComponents, 'config'>): Promise<PublisherComponent> {
export async function createSnsComponent({ config }: Pick<AppComponents, 'config'>): Promise<PublisherComponent> {
const snsArn = await config.requireString('AWS_SNS_ARN')
const optionalEndpoint = await config.getString('AWS_SNS_ENDPOINT')

const client = new SNSClient({
endpoint: optionalEndpoint ? optionalEndpoint : undefined,
endpoint: optionalEndpoint ? optionalEndpoint : undefined
})

async function publishMessage(event: any): Promise<void> {
const command = new PublishCommand({
TopicArn: snsArn,
Message: JSON.stringify(event),
MessageAttributes: {
type: {
DataType: 'String',
StringValue: event.type,
},
subType: {
DataType: 'String',
StringValue: event.subType,
},
async function publishMessage(event: any, attributes: { type: string; subType: string }): Promise<void> {
const command = new PublishCommand({
TopicArn: snsArn,
Message: JSON.stringify(event),
MessageAttributes: {
type: {
DataType: 'String',
StringValue: attributes.type
},
})
subType: {
DataType: 'String',
StringValue: attributes.subType
}
}
})

await client.send(command)
await client.send(command)
}

return { publishMessage }
}
}
12 changes: 9 additions & 3 deletions consumer-server/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export async function main(program: Lifecycle.EntryPointParameters<AppComponents
const logger = components.logs.getLogger('main-loop')

components.runner.runTask(async (opt) => {
const platform = (await components.config.requireString('PLATFORM')).toLocaleLowerCase()
const platform = (await components.config.requireString('PLATFORM')).toLocaleLowerCase() as
| 'windows'
| 'mac'
| 'webgl'
while (opt.isRunning) {
if (await machineRanOutOfSpace(components)) {
logger.warn('Stopping program due to lack of disk space')
Expand Down Expand Up @@ -56,12 +59,15 @@ export async function main(program: Lifecycle.EntryPointParameters<AppComponents
key: `${job.entity.entityId}-${platform}`,
timestamp: Date.now(),
metadata: {
platform: platform as "windows" | "mac" | "webgl",
platform: platform,
entityId: job.entity.entityId
}
}

await components.publisher.publishMessage(eventToPublish)
await components.publisher.publishMessage(eventToPublish, {
type: Events.Type.ASSET_BUNDLE,
subType: Events.SubType.AssetBundle.CONVERTED
})
} finally {
components.metrics.decrement('ab_converter_running_conversion')
}
Expand Down
4 changes: 2 additions & 2 deletions consumer-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ export type HandlerContextWithPath<
export type Context<Path extends string = any> = IHttpServerComponent.PathAwareContext<GlobalContext, Path>

export type PublisherComponent = {
publishMessage(event: any): Promise<void>
}
publishMessage(event: any, attributes: { type: string; subType: string }): Promise<void>
}
16 changes: 4 additions & 12 deletions consumer-server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -751,18 +751,10 @@
eslint-plugin-prettier "^5.1.3"
prettier "^3.3.2"

"@dcl/schemas@https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/asset-bundle-events/dcl-schemas-15.1.2-11920921023.commit-b42e8e5.tgz":
version "15.1.2-11920921023.commit-b42e8e5"
resolved "https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/asset-bundle-events/dcl-schemas-15.1.2-11920921023.commit-b42e8e5.tgz#5d536bbee83ffd8bc4170d812958f541a5bbd24e"
dependencies:
ajv "^8.11.0"
ajv-errors "^3.0.0"
ajv-keywords "^5.1.0"
mitt "^3.0.1"

"@dcl/schemas@https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/asset-bundle-events/dcl-schemas-15.1.3-12164880486.commit-e79c069.tgz":
version "15.1.3-12164880486.commit-e79c069"
resolved "https://sdk-team-cdn.decentraland.org/@dcl/schemas/branch/feat/asset-bundle-events/dcl-schemas-15.1.3-12164880486.commit-e79c069.tgz#5694c4efab8f91b46661a1c9d483c52422410825"
"@dcl/schemas@^15.2.0":
version "15.2.0"
resolved "https://registry.yarnpkg.com/@dcl/schemas/-/schemas-15.2.0.tgz#9463426cc939a45e4e8dd94dc9f99b95dfc27976"
integrity sha512-sF7PWZ6Cexf9qXssY7Kt4L5qI1l/87ei4jSEMcGE4AKyI6tCgtAMr2OwHslnKp5D4zT1UliDAt239gk/+/fk7A==
dependencies:
ajv "^8.11.0"
ajv-errors "^3.0.0"
Expand Down

0 comments on commit 763e528

Please sign in to comment.