« blib/lib/auto/share/dist/Beekeeper/flood/lib/MyApp/Service/Flood.pm
↑ Summary
blib/lib/auto/share/dist/Beekeeper/scraper/client.pl »
| 1 | package MyApp::Service::Flood::Worker; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Beekeeper::Worker ':log'; | ||
| 7 | use base 'Beekeeper::Worker'; | ||
| 8 | |||
| 9 | |||
| 10 | sub authorize_request { | ||
| 11 | my ($self, $req) = @_; | ||
| 12 | |||
| 13 | return BKPR_REQUEST_AUTHORIZED; | ||
| 14 | } | ||
| 15 | |||
| 16 | sub on_startup { | ||
| 17 | my $self = shift; | ||
| 18 | |||
| 19 | $self->accept_remote_calls( | ||
| 20 | 'myapp.flood.echo' => 'echo', | ||
| 21 | 'myapp.flood.delay' => 'delayed_echo', | ||
| 22 | ); | ||
| 23 | |||
| 24 | $self->accept_notifications( | ||
| 25 | 'myapp.flood.msg' => 'message', | ||
| 26 | ); | ||
| 27 | |||
| 28 | log_info "Ready"; | ||
| 29 | } | ||
| 30 | |||
| 31 | sub on_shutdown { | ||
| 32 | my $self = shift; | ||
| 33 | |||
| 34 | log_info "Stopped"; | ||
| 35 | } | ||
| 36 | |||
| 37 | |||
| 38 | sub echo { | ||
| 39 | my ($self, $params) = @_; | ||
| 40 | |||
| 41 | return $params; | ||
| 42 | } | ||
| 43 | |||
| 44 | sub message { | ||
| 45 | my ($self, $params) = @_; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub delayed_echo { | ||
| 49 | my ($self, $params, $request) = @_; | ||
| 50 | |||
| 51 | $request->async_response; | ||
| 52 | |||
| 53 | my $timer_id = ++($self->{timer_seq}); | ||
| 54 | |||
| 55 | $self->{$timer_id} = AnyEvent->timer( | ||
| 56 | after => 1, | ||
| 57 | cb => sub { | ||
| 58 | delete $self->{$timer_id}; | ||
| 59 | $request->send_response( $params ); | ||
| 60 | }, | ||
| 61 | ); | ||
| 62 | } | ||
| 63 | |||
| 64 | 1; |