| 1 | package App::Ordo::Command::Job::Run; | ||
| 2 | use Moo; | ||
| 3 | use feature qw(say); | ||
| 4 | use Term::ANSIColor qw(colored); | ||
| 5 | |||
| 6 | extends 'App::Ordo::Command::Base'; | ||
| 7 | |||
| 8 | use App::Ordo qw($CURRENT_PATH); | ||
| 9 | |||
| 10 | sub name { "job run" } | ||
| 11 | sub summary { "Run a job immediately" } | ||
| 12 | sub usage { "<path/name>" } | ||
| 13 | sub aliases { ['job start'] } | ||
| 14 | |||
| 15 | sub option_spec { {} } | ||
| 16 | |||
| 17 | sub execute { | ||
| 18 | my ($self, $opt, $name) = @_; | ||
| 19 | |||
| 20 | unless ($name) { | ||
| 21 | say colored(["bold red"], "Usage: job run <path/name>"); | ||
| 22 | return; | ||
| 23 | } | ||
| 24 | |||
| 25 | my $res = $self->api->call('start_job', { name => $name }); | ||
| 26 | |||
| 27 | if ($res->{success}) { | ||
| 28 | say colored(["bold green"], "Job started"); | ||
| 29 | } else { | ||
| 30 | say colored(["bold red"], "Failed to start job: " . ($res->{message} || 'not found')); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | 1; |