Skip to content

Commit 94bbe4e

Browse files
authored
Merge pull request #194 from codingtools/cdt-193
cdt-193 [CRON] - improve cron scheduling
2 parents b391e69 + 67aba20 commit 94bbe4e

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

src/commands/cron.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ export default class Cron extends Command {
5656
help: flags.help({char: 'h'}),
5757
string: flags.string({char: 's' , description: 'Cron expression'}),
5858
describe: flags.boolean({char: 'd' , description: 'Describe cron expressions into human readable descriptions'}),
59-
run: flags.boolean({char: 'r' , description: 'run command using cron expression'}),
60-
command: flags.string({char: 'c' , description: 'unix command to be executed'}),
59+
run: flags.string({char: 'r' , description: 'run command using cron expression'}),
6160
}
6261

6362
static args = [{name: 'string'}]
@@ -69,8 +68,6 @@ export default class Cron extends Command {
6968
args.string = Utilities.getInputStringFromCmd(this, flags, args) // from either -s or args
7069
args.action = this.getAction(flags, args) //by default let it be sha1
7170

72-
args.command = this.getCommand(flags, args) //by default let it be sha1
73-
7471
//check params after evaluating all
7572
this.checkParameters(flags, args)
7673
this.evalCron(flags, args)
@@ -112,9 +109,9 @@ export default class Cron extends Command {
112109
if (args.action === Cron.DESCRIBE) {
113110
Logger.success(this, cronSchedule)
114111
} else if (args.action === Cron.RUN) {
115-
Logger.success(this, `running command ${chalk.green(cronSchedule)}, use ${chalk.yellow('Ctrl+C')} to exit.`)
112+
Logger.success(this, `running ${chalk.yellow(flags.run)}, ${chalk.green(cronSchedule)}, use ${chalk.yellow('Ctrl+C')} to exit.`)
116113
NodeCron.schedule(args.string, function () {
117-
shelljs.exec(args.command)
114+
shelljs.exec(flags.run)
118115
})
119116
}
120117
}
@@ -128,12 +125,4 @@ export default class Cron extends Command {
128125
Logger.error(this, 'Invalid Or Unsupported action')
129126
}
130127

131-
// tslint:disable-next-line:no-unused
132-
private getCommand(flags: any, args: any) {
133-
// we only need this if actions is run
134-
if (flags.command) // find human readable descriptions for cron
135-
return flags.command
136-
if (args.action === Cron.RUN)
137-
Logger.error(this, 'Invalid Or Unsupported Command')
138-
}
139128
}

src/commands/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class Run extends Command {
1212

1313
static flags = {
1414
help: flags.help({char: 'h'}),
15-
string: flags.string({char: 's' , description: 'unix command'}),
15+
string: flags.string({char: 's' , description: 'command to execute, should be compatible with your shell'}),
1616
}
1717

1818
static args = [{name: 'string'}]

test/commands/cron.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {expect, test} from '@oclif/test'
2+
import { exit } from 'process'
23

34
describe('cron', () => {
45
test
@@ -58,4 +59,11 @@ describe('cron', () => {
5859
expect(ctx.stdout).to.contain('At 12:00 AM, on day 12 of the month, and on Monday and Tuesday, every 2 months')
5960
})
6061

62+
// todo: have to disable it because it runs forever in git actions https://github.com/codingtools/cdt/pull/194/checks?check_run_id=2158543309
63+
// test
64+
// .stdout()
65+
// .command(['cron', '-r', 'echo hello', '*/5 * * * * *'])
66+
// .it('Cron scheduling hello every second', ctx => {
67+
// expect(ctx.stdout).to.contain('running echo hello, Every 5 seconds').
68+
// })
6169
})

0 commit comments

Comments
 (0)