Skip to content

Commit

Permalink
New pipelineWrapper without dynamic import
Browse files Browse the repository at this point in the history
  • Loading branch information
numtel committed Nov 4, 2024
1 parent 94101ff commit 572da7d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
39 changes: 38 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import https from 'node:https';
import {mkdirSync, createWriteStream, createReadStream} from 'node:fs';
import {mkdirSync, createWriteStream, createReadStream, readFileSync} from 'node:fs';
import {isAbsolute, resolve, sep} from 'node:path';
import {exec} from 'node:child_process';
import nodeUrl from 'node:url';
Expand All @@ -9,10 +9,47 @@ import {Upload} from '@aws-sdk/lib-storage';
import archiver from 'archiver';
import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator';

import {StatusReporter} from './src/StatusReporter.js';

const s3Client = new S3Client({
region: process.env.AWS_REGION,
});

export async function pipelineWrapper(handler) {
function saveResponse(requestId, obj) {
return uploadJsonToS3(
process.env.BLOB_BUCKET,
`instance-response/${requestId}.json`,
obj,
);
}
const payload = JSON.parse(readFileSync(process.argv[2], {encoding:'utf8'}));
const status = new StatusReporter(process.env.BLOB_BUCKET, `status/${payload.requestId}.json`);
status.startUploading(5000);
status.startMemoryLogs(10000);
try {
const pkgName = await handler({ payload }, { status });
await saveResponse(payload.requestId, {
statusCode: 200,
body: JSON.stringify({
pkgName,
}),
});
} catch(error) {
status.log(error.toString());
await saveResponse(payload.requestId, {
statusCode: 500,
body: JSON.stringify({
errorType: 'error',
errorMessage: error.message
}),
});
} finally {
status.stopMemoryLogs();
await status.stopUploading();
}
}

export function uniqueName(prefix) {
return `${prefix}-${uniqueNamesGenerator({
dictionaries: [adjectives, colors, animals],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "circuitscan-pipeline-runner",
"version": "0.0.8",
"version": "0.0.9",
"main": "index.js",
"type": "module",
"dependencies": {
Expand Down

0 comments on commit 572da7d

Please sign in to comment.