Skip to content

Commit f7e3e2c

Browse files
authored
Include metadata in compute jobs. Closes #1830 (#1889)
1 parent 0006764 commit f7e3e2c

7 files changed

Lines changed: 63 additions & 20 deletions

File tree

src/common/compute/backends/ComputeClient.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ define([], function() {
1212
unimplemented(this.logger, 'cancelJob');
1313
}
1414

15-
async createJob (/*hash*/) {
16-
unimplemented(this.logger, 'createJob');
15+
async startJob (/*hash, metadata*/) {
16+
unimplemented(this.logger, 'startJob');
1717
}
1818

1919
async getStatus (/*jobInfo*/) {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* globals define */
2+
define([], function() {
3+
4+
class ComputeJob {
5+
constructor (hash, name='DeepForge Job') {
6+
this.name = name;
7+
this.hash = hash;
8+
}
9+
}
10+
11+
class PipelineJob extends ComputeJob {
12+
constructor (hash, projectId, branch, core, job) {
13+
const execNode = core.getParent(job);
14+
const jobInfo = PipelineJob.getNodeMetadata(core, job);
15+
const execution = PipelineJob.getNodeMetadata(core, execNode);
16+
const name = `DeepForge Job: ${jobInfo.name} (${execution.name}) in ${projectId} (${branch})`;
17+
super(hash, name);
18+
this.job = jobInfo;
19+
this.execution = execution;
20+
this.branch = branch;
21+
this.projectId = projectId;
22+
}
23+
24+
static getNodeMetadata (core, node) {
25+
const id = core.getPath(node);
26+
const name = core.getAttribute(node, 'name');
27+
return {id, name};
28+
}
29+
}
30+
31+
return {ComputeJob, PipelineJob};
32+
});

src/common/compute/backends/gme/Client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ define([
9696
return this.executor.getInfo(job.hash);
9797
}
9898

99-
async createJob (hash) {
99+
async startJob (job) {
100100
await this.checkExecutionEnv();
101-
101+
const {hash} = job;
102102
const result = await this.executor.createJob({hash});
103103

104104
this.poll(hash);

src/common/compute/backends/local/Client.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ define([
108108
}
109109
}
110110

111-
async createJob (hash) {
111+
async startJob (job) {
112+
const {hash} = job;
112113
this.jobQueue.push(hash);
113114
this._processNextJob();
114115

@@ -143,15 +144,15 @@ define([
143144

144145
this.currentJob = this.jobQueue.shift();
145146
if (this.currentJob) {
146-
return this._createJob(this.currentJob);
147+
return this._startJob(this.currentJob);
147148
}
148149
}
149150

150151
_getWorkingDir (hash) {
151152
return path.join(os.tmpdir(), `deepforge-local-exec-${hash}`);
152153
}
153154

154-
async _createJob (hash) {
155+
async _startJob (hash) {
155156
const jobInfo = {hash};
156157
this.emit('update', jobInfo.hash, this.PENDING);
157158
const tmpdir = this._getWorkingDir(hash);

src/common/compute/backends/sciserver-compute/Client.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@ define([
3232
this.consoleOutputLen = {};
3333
}
3434

35-
async createJob (hash) {
36-
const filesInfo = await this._uploadFiles(hash);
37-
const job = await this._createJob(filesInfo);
38-
const jobInfo = {
39-
id: job.id,
40-
hash,
41-
};
35+
async startJob (job) {
36+
const filesInfo = await this._uploadFiles(job.hash);
37+
const {id} = await this._startJob(job, filesInfo);
38+
const jobInfo = {id, hash: job.hash};
4239
this._poll(jobInfo);
4340

4441
return jobInfo;
4542
}
4643

47-
async _createConfig (filesInfo) {
44+
async _createConfig (job, filesInfo) {
4845
const {dirname, volumePool, volume} = filesInfo;
4946
const domain = await this._getComputeDomain();
5047
const userVolumes = domain.userVolumes.map(volume => ({
@@ -58,7 +55,7 @@ define([
5855
dockerComputeEndpoint: domain.apiEndpoint,
5956
dockerImageName: 'DeepForge',
6057
resultsFolderURI: '',
61-
submitterDID: 'DeepForge Job',
58+
submitterDID: job.name,
6259
volumeContainers: [],
6360
userVolumes: userVolumes
6461
};
@@ -89,8 +86,8 @@ define([
8986
return filesInfo;
9087
}
9188

92-
async _createJob (filesInfo) {
93-
const config = await this._createConfig(filesInfo);
89+
async _startJob (job, filesInfo) {
90+
const config = await this._createConfig(job, filesInfo);
9491
const url = 'https://apps.sciserver.org/racm//jobm/rest/jobs/docker';
9592

9693
const opts = {

src/plugins/ExecuteJob/ExecuteJob.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ define([
2020
'q',
2121
'superagent',
2222
'underscore',
23+
'deepforge/compute/backends/ComputeJob',
2324
], function (
2425
assert,
2526
pluginMetadata,
@@ -41,9 +42,11 @@ define([
4142
Q,
4243
superagent,
4344
_,
45+
ComputeJob,
4446
) {
4547
'use strict';
4648

49+
const {PipelineJob} = ComputeJob;
4750
pluginMetadata = JSON.parse(pluginMetadata);
4851

4952
/**
@@ -510,7 +513,14 @@ define([
510513
ExecuteJob.prototype.createJob = async function (job, hash) {
511514
// Record the job info for the given hash
512515
this._execHashToJobNode[hash] = job;
513-
const jobInfo = await this.compute.createJob(hash);
516+
const computeJob = new PipelineJob(
517+
hash,
518+
this.projectId,
519+
this.branchName,
520+
this.core,
521+
job
522+
);
523+
const jobInfo = await this.compute.startJob(computeJob);
514524
this.core.setAttribute(job, 'jobInfo', JSON.stringify(jobInfo));
515525
this.core.setAttribute(job, 'execFiles', hash);
516526

src/routers/InteractiveCompute/Session.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const Channel = require('./Channel');
99
const EventEmitter = requireJS('deepforge/EventEmitter');
1010
const Message = requireJS('deepforge/compute/interactive/message');
1111
const ComputeClient = requireJS('deepforge/compute/backends/ComputeClient');
12+
const {ComputeJob} = requireJS('deepforge/compute/backends/ComputeJob');
1213

1314
class Session extends EventEmitter {
1415
constructor(blobClient, compute, clientSocket) {
@@ -36,7 +37,9 @@ class Session extends EventEmitter {
3637

3738
const files = new JobFiles(blobClient, SERVER_URL, this.id);
3839
const hash = await files.upload();
39-
this.jobInfo = this.compute.createJob(hash);
40+
const name = 'DeepForge Interactive Session';
41+
const computeJob = new ComputeJob(hash, name);
42+
this.jobInfo = this.compute.startJob(computeJob);
4043
this.compute.on('end', (id, info) => {
4144
const isError = this.clientSocket.readyState === WebSocket.OPEN &&
4245
info.status !== ComputeClient.SUCCESS;

0 commit comments

Comments
 (0)