|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { dir } from "tmp" |
18 | 17 | import { cli } from "madwizard/dist/fe/cli" |
19 | 18 | import { MadWizardOptions } from "madwizard" |
20 | | -import { Arguments, KResponse } from "@kui-shell/core" |
| 19 | +import { Arguments, encodeComponent } from "@kui-shell/core" |
21 | 20 |
|
22 | 21 | export default async function attach(args: Arguments) { |
23 | | - return new Promise<KResponse>((resolve, reject) => { |
24 | | - dir({ prefix: "logdir-stage" }, async (err, logdir) => { |
25 | | - if (err) { |
26 | | - reject(err) |
27 | | - } |
| 22 | + const options: MadWizardOptions = { store: process.env.GUIDEBOOK_STORE, clean: false } |
28 | 23 |
|
29 | | - try { |
30 | | - const options: MadWizardOptions = { store: process.env.GUIDEBOOK_STORE, clean: false } |
| 24 | + // TODO: update madwizard to accept env in the options |
| 25 | + process.env.NO_WAIT = "true" // don't wait for job termination |
| 26 | + process.env.QUIET_CONSOLE = "true" // don't tee logs to the console |
31 | 27 |
|
32 | | - // TODO: update madwizard to accept env in the options |
33 | | - process.env.LOGDIR_STAGE = logdir // stage log files here |
34 | | - process.env.NO_WAIT = "true" // don't wait for job termination |
35 | | - process.env.QUIET_CONSOLE = "true" // don't tee logs to the console |
| 28 | + const resp = await cli(["codeflare", "guide", "ml/ray/aggregator"], undefined, options) |
36 | 29 |
|
37 | | - /* const cleanup = */ await cli(["codeflare", "guide", "ml/ray/aggregator"], undefined, options) |
38 | | - /* if (typeof cleanup === 'function') { |
39 | | - onQuit(cleanup) |
40 | | - } */ |
| 30 | + const logdir = resp && resp.env ? resp.env.LOGDIR_STAGE : undefined |
41 | 31 |
|
42 | | - await args.REPL.qexec(`codeflare dashboardui -f ${logdir}`) |
| 32 | + if (logdir) { |
| 33 | + process.env.LOGDIR = logdir |
| 34 | + await args.REPL.qexec(`codeflare dashboardui -f ${encodeComponent(logdir)}`) |
| 35 | + } else { |
| 36 | + throw new Error("Could not attach, due to missing logging directory") |
| 37 | + } |
43 | 38 |
|
44 | | - // TODO: when job completes, auto-exit |
45 | | - |
46 | | - resolve(true) |
47 | | - } catch (err) { |
48 | | - console.error(err) |
49 | | - reject(err) |
50 | | - } |
51 | | - }) |
52 | | - }) |
| 39 | + // TODO: when job completes, auto-exit |
| 40 | + return true |
53 | 41 | } |
0 commit comments