Skip to content

Commit

Permalink
Save metadata in operation output dir. Closes #1917 (#1919)
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Sep 22, 2020
1 parent 674324e commit 0c7ef30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/plugins/GenerateJob/templates/main.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import json
import deepforge
import signal
import sys
import os

def signal_handler(signum, frame):
sig = signal.Signals(signum)
Expand Down Expand Up @@ -34,13 +35,13 @@ print('\n############### Running "<%= name.replace(/'/g, '\\\'') %>" Operation #
})%>)
print('############### "<%= name.replace(/'/g, '\\\'') %>" Operation Complete! ###############')

result_types = {}
<% outputs.forEach(name => { %>
with open('outputs/<%= name %>', 'wb') as outfile:
os.makedirs('outputs/<%= name %>/', exist_ok=True)
with open('outputs/<%= name %>/metadata.json', 'w') as outfile:
metadata = {}
metadata['type'] = deepforge.serialization.get_full_class_name(<%= name %>)
json.dump(metadata, outfile)
with open('outputs/<%= name %>/data', 'wb') as outfile:
deepforge.serialization.dump(<%= name %>, outfile)
result_types['<%= name %>'] = deepforge.serialization.get_full_class_name(<%= name %>)
<% }); %>

# Save the result types
with open('result-types.json', 'w') as f:
json.dump(result_types, f)
9 changes: 5 additions & 4 deletions src/plugins/GenerateJob/templates/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const childProcess = require('child_process');
const {spawn} = childProcess;
const fs = require('fs');
const fsp = fs.promises;
const {promisify} = require('util');
const mkdir = promisify(fs.mkdir);
const pipeline = promisify(require('stream').pipeline);
Expand Down Expand Up @@ -162,19 +163,19 @@ requirejs([

async function uploadOutputData(exitCode) {
if (exitCode === 0) {
const results = require('./result-types.json');
const outputNames = await fsp.readdir('./outputs');
const results = {};
const storageId = Config.storage.id;
const config = Config.storage.config;
const client = await Storage.getClient(storageId, logger, config);
const outputNames = Object.keys(results);
const storageDir = Config.storage.dir;

for (let i = outputNames.length; i--;) {
const filename = outputNames[i];
const storagePath = `${storageDir}/${filename}`;
const contentsStream = fs.createReadStream(`outputs/${filename}`);
const contentsStream = fs.createReadStream(`outputs/${filename}/data`);
const dataInfo = await client.putFileStream(storagePath, contentsStream);
const type = results[filename];
const type = require(`./outputs/${filename}/metadata.json`).type;
results[filename] = {type, dataInfo};
}

Expand Down

0 comments on commit 0c7ef30

Please sign in to comment.