This repository was archived by the owner on Jun 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsample_jobs_node_app.js
More file actions
86 lines (72 loc) · 2.55 KB
/
sample_jobs_node_app.js
File metadata and controls
86 lines (72 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Assumes you have installed the paperspace-node package globally.
// Use "require('../../paperspace-node')" if running from the repository tree.
var paperspace_node = require('paperspace-node');
// Set apkKey for use of the paperspace api
var paperspace = paperspace_node({
apiKey: '1be4f97...' // Substitue your actual apiKey here
});
// Retrieve a list of all the templates as a json array
console.log('\npaperspace.jobs.create(...);');
// Create a machine using the found template id, and the specified machine typ from above
console.log('\npaperspace.jobs.create({\n name: \'mytestjob\',\n machineType: \'GPU+\',');
console.log(' container: \'Test-Container\'}, ...);');
paperspace.jobs.create({
name: 'mytestjob',
machineType: 'GPU+',
container: 'Test-Container',
workspace: '~/myproject3',
command: './do.sh',
}, function(err, res) {
if (err) {
console.log(err);
process.exit(1);
}
console.log(res);
var id = res.id; // Extract the id of the newly created job
// Wait for job to enter the 'Stopped' state
console.log('\npaperspace.jobs.waitfor({jobId: \'' + id + '\', state: \'Stopped\'}, ...);');
paperspace.jobs.waitfor({
jobId: id,
state: 'Stopped',
}, function(err, res) {
if (err) {
console.log(err);
process.exit(1);
}
console.log(res);
console.log('\npaperspace.jobs.logs({jobId: \'' + id + '\'}, ...);');
paperspace.jobs.logs({
jobId: id,
},
function(err, res) {
if (err) {
console.log(err);
process.exit(1);
}
console.log(res);
console.log('\npaperspace.jobs.artifactsList({jobId: \'' + id + '\'}, ...);');
paperspace.jobs.artifactsList({
jobId: id,
size: true,
}, function(err, res) {
if (err) {
console.log(err);
process.exit(1);
}
console.log(res);
console.log('\npaperspace.jobs.artifactsGet({jobId: \'' + id + '\'}, ...);');
paperspace.jobs.artifactsGet({
jobId: id,
dest: '~/temp',
}, function(err, res) {
if (err) {
console.log('err: ' + err);
process.exit(1);
}
console.log(res);
console.log('done');
});
});
});
});
});