Skip to content

Commit

Permalink
chore: Add logger for has content changed task (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalkia authored Oct 24, 2024
1 parent c814d36 commit f1c5bc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions consumer-server/src/logic/conversion-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,13 @@ export async function executeConversion(

if ($BUILD_TARGET !== 'webgl') {
try {
hasContentChanged = await hasContentChange(entityId, contentServerUrl, $BUILD_TARGET, outDirectory)
hasContentChanged = await hasContentChange(entityId, contentServerUrl, $BUILD_TARGET, outDirectory, logger)
} catch (e) {
console.log('HasContentChanged failed with error ' + e)
logger.info('HasContentChanged failed with error ' + e)
}
}

console.log(`HasContentChanged for ${entityId} result was ${hasContentChanged}`)
logger.info(`HasContentChanged for ${entityId} result was ${hasContentChanged}`)

let exitCode
try {
Expand Down
11 changes: 9 additions & 2 deletions consumer-server/src/logic/has-content-changed-task.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Entity } from '@dcl/schemas'
import * as fs from 'fs'
import * as path from 'path'
import fetch from 'node-fetch' // Assuming you're using the node-fetch package
import fetch from 'node-fetch'
import { ILoggerComponent } from '@well-known-components/interfaces' // Assuming you're using the node-fetch package
async function getActiveEntity(ids: string, contentServer: string): Promise<Entity> {
const url = `${contentServer}/entities/active`

Expand Down Expand Up @@ -146,17 +147,22 @@ export async function hasContentChange(
entityId: string,
contentServerUrl: string,
buildTarget: string,
outputFolder: string
outputFolder: string,
logger: ILoggerComponent.ILogger
): Promise<boolean> {
const entity = await getActiveEntity(entityId, contentServerUrl)
if (entity.type === 'scene') {
logger.info(`HasContentChanged: Entity ${entityId} is a scene`)
const previousHash = await getLastEntityIdByBase(entity.metadata.scene.base, contentServerUrl)
if (previousHash !== null) {
logger.info(`HasContentChanged: Previous hash is ${previousHash}`)
const manifest = await getManifestFiles(previousHash, buildTarget)
if (manifest !== null) {
logger.info(`HasContentChanged: Manifest exists for hash ${previousHash}`)
const hashes = extractValidHashesFromEntity(entity.content)
const doesEntityMatchHashes = AreAllContentHashesInManifest(hashes, manifest.files)
if (doesEntityMatchHashes) {
logger.info(`HasContentChanged: All entities contained in old manifest`)
const allFilesDownloadSuccesfully = await downloadFilesFromManifestSuccesfully(
hashes,
manifest.version,
Expand All @@ -168,6 +174,7 @@ export async function hasContentChange(
if (allFilesDownloadSuccesfully) {
return false
} else {
logger.info(`HasContentChanged: Some downloads failed`)
//In case we downloaded some file, remove the corrupt state
await DeleteFilesInOutputFolder(outputFolder)
}
Expand Down

0 comments on commit f1c5bc0

Please sign in to comment.