-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjob.ts
More file actions
33 lines (27 loc) · 1 KB
/
job.ts
File metadata and controls
33 lines (27 loc) · 1 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
import { FancyString } from '../../src/verba/verbaString/types'
import { createGFError } from 'good-flow'
import logger from './log'
import { sleep } from './util'
const log = logger.child({ code: 'JOB', indent: 2 })
export const doJob = async (jobName: string) => {
const baseLogText: FancyString = c => `Doing job ${c.cyan(jobName)}`
const spinner = log.spinner({
text: baseLogText,
})
if (jobName.indexOf('!') !== -1) {
spinner.persist()
throw createGFError({
msg: f => `Job name invalid. Recieved: ${f.cyan(jobName)}.`,
advice: { tips: 'Job names must only contain alphanumeric and \'_\' characters.' },
})
}
for (let i = 0; i < 100; i += 20) {
// eslint-disable-next-line no-await-in-loop
await sleep(0.1)
// Every other update is logged if terminal is not TTY.
// Test isTty flag for spinner.text
spinner.text([baseLogText, c => ` | ${c.bold(i.toString())}%`], i % 40 === 0)
}
spinner.clear()
log.success(c => `Completed job ${c.cyan(jobName)}`)
}