-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
157 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { AsyncQueue } from '@well-known-components/pushable-channel' | ||
import { AppComponents, QueueService } from '../types' | ||
|
||
export function createMemoryQueueAdapter({ logs }: Pick<AppComponents, 'logs'>): QueueService { | ||
const logger = logs.getLogger('memory-queue') | ||
const queue = new AsyncQueue((action) => void 0) | ||
|
||
logger.info('Initializing memory queue adapter') | ||
|
||
async function send(message: any) { | ||
await queue.enqueue(message) | ||
} | ||
|
||
async function receiveSingleMessage() { | ||
const message = (await queue.next()).value | ||
return message ? [message] : [] | ||
} | ||
|
||
async function deleteMessage() { | ||
// noop | ||
} | ||
|
||
return { | ||
send, | ||
receiveSingleMessage, | ||
deleteMessage | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { exec } from 'child_process' | ||
import path from 'path' | ||
import os from 'os' | ||
import fs from 'fs' | ||
|
||
import { LodGeneratorService } from '../types' | ||
|
||
export function createLodGeneratorComponent(): LodGeneratorService { | ||
const projectRoot = path.resolve(__dirname, '..', '..', '..') // project root according to Dockerfile bundling | ||
const lodGeneratorProgram = path.join(projectRoot, 'api', 'DCL_PiXYZ.exe') // path to the lod generator program | ||
const sceneLodEntitiesManifestBuilder = path.join(projectRoot, 'scene-lod') // path to the scene lod entities manifest builder | ||
|
||
async function generate(entityId: string, basePointer: string): Promise<string[]> { | ||
const outputPath = path.join(os.tmpdir(), entityId) | ||
|
||
if (!fs.existsSync(outputPath)) { | ||
fs.mkdirSync(outputPath, { recursive: true }); | ||
} | ||
|
||
const commandToExecute = `${lodGeneratorProgram} "coords" "${basePointer}" ${sceneLodEntitiesManifestBuilder} "${outputPath}"` | ||
const files: string[] = await new Promise((resolve, reject) => { | ||
exec(commandToExecute, (_error, _stdout, _stderr) => { | ||
const generatedFiles = fs.readdirSync(outputPath) | ||
// if files exists return otherwise reject | ||
if (generatedFiles.length > 0) { | ||
resolve(generatedFiles) | ||
} else { | ||
reject() | ||
} | ||
}) | ||
}) | ||
|
||
fs.rmdirSync(outputPath) | ||
return files | ||
} | ||
|
||
return { generate } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { AppComponents, MessageHandler } from '../types' | ||
|
||
export function createMessageHandlerComponent({ | ||
logs, | ||
lodGenerator | ||
}: Pick<AppComponents, 'logs' | 'lodGenerator'>): MessageHandler { | ||
const logger = logs.getLogger('message-handler') | ||
|
||
async function handle(message: { Message: string }): Promise<void> { | ||
const parsedMessage = JSON.parse(message.Message) | ||
|
||
if (parsedMessage.entityType !== 'scene') { | ||
return | ||
} | ||
|
||
const { base, entityId } = parsedMessage | ||
|
||
try { | ||
const result = await lodGenerator.generate(entityId, base) | ||
logger.info('LODs correctly generated', { files: result.join(', '), entityId }) | ||
} catch (error: any) { | ||
logger.error('Failed while generating LODs', { error: error.message, entityId }) | ||
} | ||
} | ||
|
||
return { handle } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters