-
Notifications
You must be signed in to change notification settings - Fork 0
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
6 changed files
with
120 additions
and
44 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
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,70 @@ | ||
import { exec } from 'child_process' | ||
import path from 'path' | ||
import fs from 'fs' | ||
import os from 'os' | ||
|
||
import { AppComponents } from '../types' | ||
|
||
const projectRoot = path.resolve(__dirname, '..', '..', '..') | ||
const lodGeneratorProgram = path.join(projectRoot, 'api', 'DCL_PiXYZ.exe') | ||
const sceneLodEntitiesManifestBuilder = path.join(projectRoot, 'scene-lod') | ||
|
||
export async function validate({ logs }: Pick<AppComponents, 'logs'>): Promise<void> { | ||
const logger = logs.getLogger('boot-validator') | ||
|
||
logger.info('Validating boot...') | ||
|
||
logger.info('Checking if PiXYZ is present at', { lodGeneratorProgram }) | ||
if (fs.existsSync(lodGeneratorProgram)) { | ||
logger.info('PiXYZ program found') | ||
} else { | ||
logger.error('PiXYZ program not found') | ||
} | ||
|
||
if (fs.existsSync(sceneLodEntitiesManifestBuilder)) { | ||
logger.info('Scene LOD Entities directory found') | ||
} else { | ||
logger.error('Scene LOD Entities directory not found') | ||
} | ||
|
||
if (fs.existsSync(lodGeneratorProgram) && fs.existsSync(sceneLodEntitiesManifestBuilder)) { | ||
logger.info('Executing test case...') | ||
const outputPath = path.join(os.tmpdir(), 'output'); | ||
if (!fs.existsSync(outputPath)) { | ||
fs.mkdirSync(outputPath); | ||
} | ||
|
||
const command = `${lodGeneratorProgram} "coords" "-129,-77" "50" ${sceneLodEntitiesManifestBuilder} "${outputPath}"` | ||
// trigger exec asynchronously | ||
await Promise.all([ | ||
new Promise((resolve, _) => { | ||
logger.info('Triggering command') | ||
return exec(command, (error, stdout, stderr) => { | ||
if (error) { | ||
logger.error(`exec error: ${error}`) | ||
resolve(false) | ||
} | ||
logger.info(`stdout: ${stdout}`) | ||
logger.error(`stderr: ${stderr}`) | ||
resolve(true) | ||
}) | ||
}) | ||
]) | ||
|
||
// await new Promise((resolve, reject) => { | ||
// exec(command, (error, stdout, stderr) => { | ||
// if (error) { | ||
// logger.error(`exec error: ${error}`) | ||
// resolve(false) | ||
// } | ||
// logger.info(`stdout: ${stdout}`) | ||
// logger.error(`stderr: ${stderr}`) | ||
// resolve(true) | ||
// }) | ||
// }) | ||
// list files from outputPath | ||
const files = fs.readdirSync(outputPath) | ||
logger.info('Output files:', { files: JSON.stringify(files, null, 2) }) | ||
} | ||
process.exit(0) | ||
} |
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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
import { AppComponents, QueueWorker } from '../types' | ||
// import { AppComponents, QueueWorker } from '../types' | ||
|
||
export async function createMessagesConsumerComponent({ | ||
logs, | ||
queue | ||
}: Pick<AppComponents, 'logs' | 'queue'>): Promise<QueueWorker> { | ||
const logger = logs.getLogger('messages-consumer') | ||
// export async function createMessagesConsumerComponent({ | ||
// logs, | ||
// queue | ||
// }: Pick<AppComponents, 'logs' | 'queue'>): Promise<QueueWorker> { | ||
// const logger = logs.getLogger('messages-consumer') | ||
|
||
async function start() { | ||
while (true) { | ||
const messages = await queue.receiveSingleMessage() | ||
for (const message of messages) { | ||
const { MessageId, Body, ReceiptHandle } = message | ||
// async function start() { | ||
// while (true) { | ||
// const messages = await queue.receiveSingleMessage() | ||
// for (const message of messages) { | ||
// const { MessageId, Body, ReceiptHandle } = message | ||
|
||
try { | ||
const parsedMessage: { Message: string } = JSON.parse(Body!) | ||
logger.info('Handling message from queue', { | ||
id: MessageId!, | ||
message: parsedMessage.Message | ||
}) | ||
} catch (error: any) { | ||
logger.error('Failed while handling message from queue', { | ||
id: MessageId!, | ||
error | ||
}) | ||
} finally { | ||
await queue.deleteMessage(ReceiptHandle!) | ||
} | ||
} | ||
} | ||
} | ||
// try { | ||
// const parsedMessage: { Message: string } = JSON.parse(Body!) | ||
// logger.info('Handling message from queue', { | ||
// id: MessageId!, | ||
// message: parsedMessage.Message | ||
// }) | ||
// } catch (error: any) { | ||
// logger.error('Failed while handling message from queue', { | ||
// id: MessageId!, | ||
// error | ||
// }) | ||
// } finally { | ||
// await queue.deleteMessage(ReceiptHandle!) | ||
// } | ||
// } | ||
// } | ||
// } | ||
|
||
return { | ||
start | ||
} | ||
} | ||
// return { | ||
// start | ||
// } | ||
// } |
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