« blib/lib/Beekeeper/JSONRPC/Request.pm
↑ Summary
blib/lib/auto/share/dist/Beekeeper/chat/lib/MyApp/Service/Chat/Worker.pm »
| 1 | package Beekeeper::Service::Supervisor; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | our $VERSION = '0.09'; | ||
| 7 | |||
| 8 | use Beekeeper::Client; | ||
| 9 | |||
| 10 | # Show errors from perspective of caller | ||
| 11 | $Carp::Internal{(__PACKAGE__)}++; | ||
| 12 | |||
| 13 | |||
| 14 | sub restart_pool { | ||
| 15 | my ($class, %args) = @_; | ||
| 16 | |||
| 17 | my $client = Beekeeper::Client->instance; | ||
| 18 | my $guard = $client->__use_authorization_token('BKPR_ADMIN'); | ||
| 19 | |||
| 20 | $client->send_notification( | ||
| 21 | method => '_bkpr.supervisor.restart_pool', | ||
| 22 | params => \%args, | ||
| 23 | ); | ||
| 24 | } | ||
| 25 | |||
| 26 | sub restart_workers { | ||
| 27 | my ($class, %args) = @_; | ||
| 28 | |||
| 29 | my $client = Beekeeper::Client->instance; | ||
| 30 | my $guard = $client->__use_authorization_token('BKPR_ADMIN'); | ||
| 31 | |||
| 32 | $client->send_notification( | ||
| 33 | method => '_bkpr.supervisor.restart_workers', | ||
| 34 | params => \%args, | ||
| 35 | ); | ||
| 36 | } | ||
| 37 | |||
| 38 | sub get_workers_status { | ||
| 39 | my ($class, %args) = @_; | ||
| 40 | |||
| 41 | my $client = Beekeeper::Client->instance; | ||
| 42 | my $guard = $client->__use_authorization_token('BKPR_ADMIN'); | ||
| 43 | my $timeout = delete $args{'timeout'}; | ||
| 44 | |||
| 45 | my $resp = $client->call_remote( | ||
| 46 | method => '_bkpr.supervisor.get_workers_status', | ||
| 47 | params => \%args, | ||
| 48 | timeout => $timeout, | ||
| 49 | ); | ||
| 50 | |||
| 51 | return $resp->result; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub get_workers_status_async { | ||
| 55 | my ($class, %args) = @_; | ||
| 56 | |||
| 57 | my $on_success = delete $args{'on_success'}; | ||
| 58 | my $on_error = delete $args{'on_error'}; | ||
| 59 | |||
| 60 | unless ($on_error) { | ||
| 61 | my ($file, $line) = (caller)[1,2]; | ||
| 62 | $on_error = sub { die $_[0]->message . " at $file line $line\n"; }; | ||
| 63 | } | ||
| 64 | |||
| 65 | my $client = Beekeeper::Client->instance; | ||
| 66 | my $guard = $client->__use_authorization_token('BKPR_ADMIN'); | ||
| 67 | my $timeout = delete $args{'timeout'}; | ||
| 68 | |||
| 69 | $client->call_remote_async( | ||
| 70 | method => '_bkpr.supervisor.get_workers_status', | ||
| 71 | params => \%args, | ||
| 72 | timeout => $timeout, | ||
| 73 | on_success => $on_success, | ||
| 74 | on_error => $on_error, | ||
| 75 | ); | ||
| 76 | } | ||
| 77 | |||
| 78 | sub get_services_status { | ||
| 79 | my ($class, %args) = @_; | ||
| 80 | |||
| 81 | my $client = Beekeeper::Client->instance; | ||
| 82 | my $guard = $client->__use_authorization_token('BKPR_ADMIN'); | ||
| 83 | my $timeout = delete $args{'timeout'}; | ||
| 84 | |||
| 85 | my $resp = $client->call_remote( | ||
| 86 | method => '_bkpr.supervisor.get_services_status', | ||
| 87 | params => \%args, | ||
| 88 | timeout => $timeout, | ||
| 89 | ); | ||
| 90 | |||
| 91 | return $resp->result; | ||
| 92 | } | ||
| 93 | |||
| 94 | sub get_services_status_async { | ||
| 95 | my ($class, %args) = @_; | ||
| 96 | |||
| 97 | my $on_success = delete $args{'on_success'}; | ||
| 98 | my $on_error = delete $args{'on_error'}; | ||
| 99 | |||
| 100 | unless ($on_error) { | ||
| 101 | my ($file, $line) = (caller)[1,2]; | ||
| 102 | $on_error = sub { die $_[0]->message . " at $file line $line\n"; }; | ||
| 103 | } | ||
| 104 | |||
| 105 | my $client = Beekeeper::Client->instance; | ||
| 106 | my $guard = $client->__use_authorization_token('BKPR_ADMIN'); | ||
| 107 | my $timeout = delete $args{'timeout'}; | ||
| 108 | |||
| 109 | $client->call_remote_async( | ||
| 110 | method => '_bkpr.supervisor.get_services_status', | ||
| 111 | params => \%args, | ||
| 112 | timeout => $timeout, | ||
| 113 | on_success => $on_success, | ||
| 114 | on_error => $on_error, | ||
| 115 | ); | ||
| 116 | } | ||
| 117 | |||
| 118 | 1; | ||
| 119 | |||
| 120 | __END__ |