Skip to content

Commit

Permalink
Add setEnvVar to interactive compute. Closes #1817 (#1820)
Browse files Browse the repository at this point in the history
  • Loading branch information
brollb committed Jul 29, 2020
2 parents c4ea35d + b4b9eaa commit 7108107
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/common/compute/interactive/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
}
}(this, function() {
const Constants = makeEnum('STDOUT', 'STDERR', 'RUN', 'ADD_ARTIFACT',
'ADD_FILE', 'ADD_USER_DATA', 'COMPLETE', 'ERROR');
'ADD_FILE', 'ADD_USER_DATA', 'COMPLETE', 'ERROR', 'SET_ENV');

function makeEnum() {
const names = Array.prototype.slice.call(arguments);
Expand Down
7 changes: 7 additions & 0 deletions src/common/compute/interactive/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ define([
await this.runTask(task);
}

async setEnvVar(name, value) {
this.ensureIdle('set env var');
const msg = new Message(Message.SET_ENV, [name, value]);
const task = new Task(this.ws, msg);
await this.runTask(task);
}

close() {
this.ws.close();
}
Expand Down
13 changes: 10 additions & 3 deletions src/routers/InteractiveCompute/job-files/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ class InteractiveClient {
this.runTask(saveArtifact);
});
} else if (msg.type === Message.ADD_FILE) {
this.runTask(() => this.writeFile(msg));
this.runTask(() => {
const [filepath, content] = msg.data;
this.writeFile(filepath, content);
});
} else if (msg.type === Message.SET_ENV) {
this.runTask(() => {
const [name, value] = msg.data;
process.env[name] = value;
});
}
}

async writeFile(msg) {
const [filepath, content] = msg.data;
async writeFile(filepath, content) {
const dirs = path.dirname(filepath).split(path.sep);
await mkdirp(...dirs);
await fs.writeFile(filepath, content);
Expand Down

0 comments on commit 7108107

Please sign in to comment.