Skip to content

Commit 28516f2

Browse files
committed
cdt-193 [CRON] - improve cron scheduling
1 parent b391e69 commit 28516f2

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ describe('cron', () => {
5858
expect(ctx.stdout).to.contain('At 12:00 AM, on day 12 of the month, and on Monday and Tuesday, every 2 months')
5959
})
6060

61+
test
62+
.stdout()
63+
.command(['cron', '-r', 'echo hello', '*/5 * * * * *'])
64+
.it('Cron scheduling hello every second', ctx => {
65+
expect(ctx.stdout).to.contain('running echo hello, Every 5 seconds')
66+
})
6167
})

0 commit comments

Comments
 (0)