From b4b9eaa8eba2c28497ad91ddb8ffa91363eb5fe2 Mon Sep 17 00:00:00 2001 From: Brian Broll Date: Wed, 29 Jul 2020 09:01:47 -0500 Subject: [PATCH] Add setEnvVar to interactive compute. Closes #1817 --- src/common/compute/interactive/message.js | 2 +- src/common/compute/interactive/session.js | 7 +++++++ src/routers/InteractiveCompute/job-files/start.js | 13 ++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/common/compute/interactive/message.js b/src/common/compute/interactive/message.js index b98d87d65..50299f963 100644 --- a/src/common/compute/interactive/message.js +++ b/src/common/compute/interactive/message.js @@ -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); diff --git a/src/common/compute/interactive/session.js b/src/common/compute/interactive/session.js index 458b05969..9ec70b820 100644 --- a/src/common/compute/interactive/session.js +++ b/src/common/compute/interactive/session.js @@ -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(); } diff --git a/src/routers/InteractiveCompute/job-files/start.js b/src/routers/InteractiveCompute/job-files/start.js index a3362ef7f..d0b10aad2 100644 --- a/src/routers/InteractiveCompute/job-files/start.js +++ b/src/routers/InteractiveCompute/job-files/start.js @@ -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);