Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #181 from davidahouse/house/180/support-artifact-c…
Browse files Browse the repository at this point in the history
…ontents

✨ Worker now returns metadata & artifact contents if specified
  • Loading branch information
davidahouse authored Sep 13, 2020
2 parents 4388612 + 502c335 commit fa35f35
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion bin/stampede-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,52 @@ async function handleTask(task, responseQueue) {
JSON.stringify(task, null, 2)
);
}

// Load any metadata pointed to by an artifact
if (task.result.artifacts != null) {
for (let aindex = 0; aindex < task.result.artifacts.length; aindex++) {
if (task.result.artifacts[aindex].metadata_file != null) {
try {
const metadata = JSON.parse(
fs.readFileSync(
directory + "/" + task.result.artifacts[aindex].metadata_file
)
);
task.result.artifacts[aindex].metadata = metadata;
} catch (e) {
logger.error(
"Error reading metadata json file: " +
directory +
"/" +
task.result.artifacts[aindex].metadata_file +
" " +
e
);
}
}

if (task.result.artifacts[aindex].contents_file != null) {
try {
const contents = JSON.parse(
fs.readFileSync(
directory + "/" + task.result.artifacts[aindex].contents_file
)
);
task.result.artifacts[aindex].contents = contents;
} catch (e) {
logger.error(
"Error reading contents json file: " +
directory +
"/" +
task.result.artifacts[aindex].contents_file +
" " +
e
);
}
}
}
}

logger.verbose("Updating task");
await updateTask(task, responseQueue);
workerStatus = "idle";
Expand Down Expand Up @@ -695,7 +741,7 @@ async function parseArtifactsCSV(csvFile) {
return new Promise((resolve) => {
const artifacts = [];
fs.createReadStream(csvFile)
.pipe(csv(["title", "url", "type"]))
.pipe(csv(["title", "url", "type", "metadata_file", "contents_file"]))
.on("data", (data) => artifacts.push(data))
.on("end", () => {
resolve(artifacts);
Expand Down

0 comments on commit fa35f35

Please sign in to comment.