Skip to content

Commit

Permalink
feat: enhance reported conversion event (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleortega authored Dec 17, 2024
1 parent d39434f commit 8a354aa
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ErrorCodes
DOWNLOAD_FAILED,
INVALID_PLATFORM,
GLTF_PROCESS_MISMATCH,
CONVERSION_ERRORS_TOLERATED
CONVERSION_ERRORS_TOLERATED,
ALREADY_CONVERTED
}
}
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": "^15.2.0",
"@dcl/schemas": "15.3.3",
"@sentry/node": "^8.27.0",
"@well-known-components/env-config-provider": "^1.2.0",
"@well-known-components/http-server": "^2.1.0",
Expand Down
16 changes: 10 additions & 6 deletions consumer-server/src/logic/conversion-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function executeLODConversion(
components: Pick<AppComponents, 'logs' | 'metrics' | 'config' | 'cdnS3'>,
entityId: string,
lods: string[]
) {
): Promise<number> {
const $LOGS_BUCKET = await components.config.getString('LOGS_BUCKET')
const $UNITY_PATH = await components.config.requireString('UNITY_PATH')
const $PROJECT_PATH = await components.config.requireString('PROJECT_PATH')
Expand All @@ -105,7 +105,7 @@ export async function executeLODConversion(

if (!unityBuildTarget) {
logger.error('Could not find a build target', { ...defaultLoggerMetadata } as any)
return
return 5 // UNEXPECTED_ERROR exit code
}

try {
Expand All @@ -128,7 +128,7 @@ export async function executeLODConversion(
// this is an error, if succeeded, we should see at least a manifest file
components.metrics.increment('ab_converter_empty_conversion', { ab_version: $AB_VERSION })
logger.error('Empty conversion', { ...defaultLoggerMetadata } as any)
return
return 5 // UNEXPECTED_ERROR exit code
}

await uploadDir(components.cdnS3, cdnBucket, outDirectory, 'LOD', {
Expand All @@ -145,6 +145,8 @@ export async function executeLODConversion(
}
]
})

return exitCode ?? -1
} catch (error: any) {
logger.debug(await promises.readFile(logFile, 'utf8'), defaultLoggerMetadata)
components.metrics.increment('ab_converter_exit_codes', { exit_code: 'FAIL' })
Expand Down Expand Up @@ -201,7 +203,7 @@ export async function executeConversion(
contentServerUrl: string,
force: boolean | undefined,
animation: string | undefined
) {
): Promise<number> {
const $LOGS_BUCKET = await components.config.getString('LOGS_BUCKET')
const $UNITY_PATH = await components.config.requireString('UNITY_PATH')
const $PROJECT_PATH = await components.config.requireString('PROJECT_PATH')
Expand All @@ -214,13 +216,13 @@ export async function executeConversion(
const unityBuildTarget = getUnityBuildTarget($BUILD_TARGET)
if (!unityBuildTarget) {
logger.info('Invalid build target ' + $BUILD_TARGET)
return
return 5 // UNEXPECTED_ERROR exit code
}

if (!force) {
if (await shouldIgnoreConversion(components, entityId, $AB_VERSION, $BUILD_TARGET)) {
logger.info('Ignoring conversion', { entityId, contentServerUrl, $AB_VERSION })
return
return 13 // ALREADY_CONVERTED exit code
}
} else {
logger.info('Forcing conversion', { entityId, contentServerUrl, $AB_VERSION })
Expand Down Expand Up @@ -347,6 +349,8 @@ export async function executeConversion(
process.exit(1)
}
}

return exitCode ?? -1
} catch (err: any) {
logger.debug(await promises.readFile(logFile, 'utf8'), defaultLoggerMetadata)
components.metrics.increment('ab_converter_exit_codes', { exit_code: 'FAIL' })
Expand Down
13 changes: 8 additions & 5 deletions consumer-server/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupRouter } from './controllers/routes'
import { executeConversion, executeLODConversion } from './logic/conversion-task'
import checkDiskSpace from 'check-disk-space'
import { AppComponents, GlobalContext, TestComponents } from './types'
import { AssetBundleConvertedEvent, Events } from '@dcl/schemas'
import { AssetBundleConversionFinishedEvent, Events } from '@dcl/schemas'

// this function wires the business logic (adapters & controllers) with the components (ports)
export async function main(program: Lifecycle.EntryPointParameters<AppComponents | TestComponents>) {
Expand Down Expand Up @@ -39,12 +39,13 @@ export async function main(program: Lifecycle.EntryPointParameters<AppComponents
}

await components.taskQueue.consumeAndProcessJob(async (job, _message) => {
let statusCode: number
try {
components.metrics.increment('ab_converter_running_conversion')
if (job.lods) {
await executeLODConversion(components, job.entity.entityId, job.lods)
statusCode = await executeLODConversion(components, job.entity.entityId, job.lods)
} else {
await executeConversion(
statusCode = await executeConversion(
components,
job.entity.entityId,
job.contentServerUrls![0],
Expand All @@ -53,14 +54,16 @@ export async function main(program: Lifecycle.EntryPointParameters<AppComponents
)
}

const eventToPublish: AssetBundleConvertedEvent = {
const eventToPublish: AssetBundleConversionFinishedEvent = {
type: Events.Type.ASSET_BUNDLE,
subType: Events.SubType.AssetBundle.CONVERTED,
key: `${job.entity.entityId}-${platform}`,
timestamp: Date.now(),
metadata: {
platform: platform,
entityId: job.entity.entityId
entityId: job.entity.entityId,
isLods: !!job.lods,
statusCode
}
}

Expand Down
8 changes: 4 additions & 4 deletions consumer-server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,10 @@
eslint-plugin-prettier "^5.1.3"
prettier "^3.3.2"

"@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==
"@dcl/schemas@15.3.3":
version "15.3.3"
resolved "https://registry.yarnpkg.com/@dcl/schemas/-/schemas-15.3.3.tgz#29b35d4eb1af0085cb09e79ecdc39a0c074f59a9"
integrity sha512-AID1yUW7gvaE5abZrW8ATK6CA941KoHn4eFWauVCQINqTSfTgp1kBlCO3fYs+26di1tcJHI8XWvR2fuf3Q084w==
dependencies:
ajv "^8.11.0"
ajv-errors "^3.0.0"
Expand Down

0 comments on commit 8a354aa

Please sign in to comment.