1 | ;
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | /**
|
4 | * Class representing a task
|
5 | */
|
6 | class Task {
|
7 | /**
|
8 | * Create a task
|
9 | * @param {Modem} modem Modem to connect to the remote service
|
10 | * @param {string} id Id of the task (optional)
|
11 | */
|
12 | constructor(modem, id) {
|
13 | this.data = {};
|
14 | this.modem = modem;
|
15 | this.id = id;
|
16 | }
|
17 | /**
|
18 | * Get low-level information on a task
|
19 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/inspect-a-task
|
20 | * The reason why this module isn't called inspect is because that interferes with the inspect utility of task.
|
21 | * @param {Object} opts Query params in the request (optional)
|
22 | * @param {String} id ID of the task to inspect, if it's not set, use the id of the object (optional)
|
23 | * @return {Promise} Promise return the task
|
24 | */
|
25 | status(opts) {
|
26 | const call = {
|
27 | path: `/tasks/${this.id}?`,
|
28 | method: 'GET',
|
29 | options: opts,
|
30 | statusCodes: {
|
31 | 200: true,
|
32 | 404: 'no such task',
|
33 | 500: 'server error'
|
34 | }
|
35 | };
|
36 | return new Promise((resolve, reject) => {
|
37 | this.modem.dial(call, (err, conf) => {
|
38 | if (err)
|
39 | return reject(err);
|
40 | const task = new Task(this.modem, this.id);
|
41 | task.data = conf;
|
42 | resolve(task);
|
43 | });
|
44 | });
|
45 | }
|
46 | }
|
47 | exports.Task = Task;
|
48 | class default_1 {
|
49 | /**
|
50 | * Create a task
|
51 | * @param {Modem} modem Modem to connect to the remote service
|
52 | * @param {string} id Id of the task (optional)
|
53 | */
|
54 | constructor(modem) {
|
55 | this.modem = modem;
|
56 | }
|
57 | /**
|
58 | * Get a Task object
|
59 | * @param {id} string ID of the secret
|
60 | * @return {Task}
|
61 | */
|
62 | get(id) {
|
63 | return new Task(this.modem, id);
|
64 | }
|
65 | /**
|
66 | * Get the list of tasks
|
67 | * https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/#/list-tasks
|
68 | * @param {Object} opts Query params in the request (optional)
|
69 | * @return {Promise} Promise returning the result as a list of tasks
|
70 | */
|
71 | list(opts) {
|
72 | const call = {
|
73 | path: '/tasks?',
|
74 | method: 'GET',
|
75 | options: opts,
|
76 | statusCodes: {
|
77 | 200: true,
|
78 | 500: 'server error'
|
79 | }
|
80 | };
|
81 | return new Promise((resolve, reject) => {
|
82 | this.modem.dial(call, (err, result) => {
|
83 | if (err)
|
84 | return reject(err);
|
85 | if (!result || !result.length)
|
86 | return resolve([]);
|
87 | resolve(result.map((conf) => {
|
88 | const task = new Task(this.modem, conf.ID);
|
89 | task.data = conf;
|
90 | return task;
|
91 | }));
|
92 | });
|
93 | });
|
94 | }
|
95 | }
|
96 | exports.default = default_1;
|
97 | //# sourceMappingURL=task.js.map |
\ | No newline at end of file |