LP#1729610: Add a service useful for testing behavior in slow response conditions
[OpenSRF.git] / src / perl / lib / OpenSRF / Application / Slooooooow.pm
1 package OpenSRF::Application::Slooooooow;
2 use base qw/OpenSRF::Application/;
3 use OpenSRF::Application;
4
5 use OpenSRF::Utils::SettingsClient;
6 use OpenSRF::EX qw/:try/;
7 use OpenSRF::Utils qw/:common/;
8 use OpenSRF::Utils::Logger;
9
10 my $log;
11
12 sub initialize {
13     $log = 'OpenSRF::Utils::Logger';
14 }
15
16 sub child_init {}
17
18 sub wait_for_it {
19     my $self = shift;
20     my $client = shift;
21     my $pause = shift;
22
23     $pause =~ s/\D//g if (defined $pause);
24     $pause //= 1;
25
26     $log->info("Holding for $pause seconds...");
27     sleep($pause);
28     $log->info("Done waiting, time to return.");
29     return [$pause, @_]
30 }
31 __PACKAGE__->register_method(
32     api_name        => 'opensrf.slooooooow.wait',
33     method          => 'wait_for_it',
34     argc            => 1,
35     signature       => {
36         params => [
37             {name => "pause", type => "number", desc => "Seconds to sleep, can be fractional"},
38             {name => "extra", type => "string", desc => "Extra optional parameter used to inflate the payload size"}
39         ],
40         return => {
41             desc => "Array of passed parameters",
42             type => "array"
43         }
44     }
45
46 );
47
48 1;