| 1 | # lib/App/Ordo/Command/Sync.pm | ||
| 2 | package App::Ordo::Command::Sync; | ||
| 3 | use Moo; | ||
| 4 | use feature qw(say); | ||
| 5 | use utf8; | ||
| 6 | use open ':std', ':utf8'; | ||
| 7 | extends 'App::Ordo::Command::Base'; | ||
| 8 | |||
| 9 | use Term::ANSIColor qw(colored); | ||
| 10 | |||
| 11 | sub name { "sync" } | ||
| 12 | sub summary { "Sync scheduler state with remote servers and detect zombie jobs" } | ||
| 13 | sub usage { "" } | ||
| 14 | |||
| 15 | sub option_spec { {} } | ||
| 16 | |||
| 17 | sub execute { | ||
| 18 | my ($self) = @_; | ||
| 19 | |||
| 20 | say colored(["bold yellow"], "Synchronizing with all remote servers..."); | ||
| 21 | |||
| 22 | my $res = $self->api->call('sync', {}); | ||
| 23 | |||
| 24 | unless ($res->{success}) { | ||
| 25 | say colored(["bold red"], "Sync failed: " . ($res->{message} || 'unknown error')); | ||
| 26 | return; | ||
| 27 | } | ||
| 28 | |||
| 29 | my $msg = $res->{message} || "sync completed"; | ||
| 30 | my ($zombies, $revived) = $msg =~ /(\d+) zombies? found.*?(\d+) revived/; | ||
| 31 | |||
| 32 | if ($zombies && $zombies > 0) { | ||
| 33 | say colored(["bold red"], "$zombies zombie job(s) detected and marked"); | ||
| 34 | say colored(["yellow"], "$revived job(s) revived") if $revived; | ||
| 35 | } else { | ||
| 36 | say colored(["bold green"], "All good - no zombies found"); | ||
| 37 | } | ||
| 38 | |||
| 39 | say colored(["bright_black"], $msg); | ||
| 40 | } | ||
| 41 | |||
| 42 | 1; |