Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setEnvVar to interactive compute. Closes #1817 #1820

Merged
merged 1 commit into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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