line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PawsX::Waiter; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
219676
|
use strict; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
47
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
754
|
use Moose::Role; |
|
2
|
|
|
|
|
673547
|
|
|
2
|
|
|
|
|
6
|
|
7
|
2
|
|
|
2
|
|
10587
|
use JSON; |
|
2
|
|
|
|
|
17163
|
|
|
2
|
|
|
|
|
9
|
|
8
|
2
|
|
|
2
|
|
1505
|
use Path::Tiny; |
|
2
|
|
|
|
|
17400
|
|
|
2
|
|
|
|
|
94
|
|
9
|
2
|
|
|
2
|
|
764
|
use PawsX::Waiter::Client; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
362
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub GetWaiter { |
14
|
3
|
|
|
3
|
1
|
8908
|
my ( $self, $waiter ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
|
|
12
|
my $version = $self->version; |
17
|
3
|
|
|
|
|
14
|
my $waiter_file = path(__FILE__)->parent->child('Waiter/waiters.json'); |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
|
|
364
|
my $service = lc $self->service; |
20
|
3
|
|
|
|
|
17
|
my $definition = $waiter_file->slurp(); |
21
|
3
|
|
|
|
|
2383
|
my $waiter_struct = JSON->new->utf8(1)->decode($definition); |
22
|
|
|
|
|
|
|
|
23
|
3
|
50
|
|
|
|
26
|
if ( my $config = $waiter_struct->{$service}->{$version}->{$waiter} ) { |
24
|
|
|
|
|
|
|
return PawsX::Waiter::Client->new( |
25
|
|
|
|
|
|
|
client => $self, |
26
|
|
|
|
|
|
|
delay => $config->{'delay'}, |
27
|
|
|
|
|
|
|
maxAttempts => $config->{'maxAttempts'}, |
28
|
|
|
|
|
|
|
operation => $config->{'operation'}, |
29
|
3
|
|
|
|
|
28
|
acceptors => $config->{'acceptors'}, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
die "Invalid waiter: " . $waiter; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
__END__ |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=encoding utf-8 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
PawsX::Waiter - A Waiter library for Paws |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
46
|
|
|
|
|
|
|
use PawsX::Waiter; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $client = Paws->new( |
49
|
|
|
|
|
|
|
config => { |
50
|
|
|
|
|
|
|
region => 'ap-south-1' |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $service = $client->service('ELB'); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Apply waiter role to Paws class |
57
|
|
|
|
|
|
|
PawsX::Waiter->meta->apply($service); |
58
|
|
|
|
|
|
|
my $response = $service->RegisterInstancesWithLoadBalancer( |
59
|
|
|
|
|
|
|
LoadBalancerName => 'test-elb', |
60
|
|
|
|
|
|
|
Instances => [ { InstanceId => 'i-0xxxxx' } ] |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $waiter = $service->GetWaiter('InstanceInService'); |
64
|
|
|
|
|
|
|
$waiter->wait( |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
LoadBalancerName => 'test-elb', |
67
|
|
|
|
|
|
|
Instances => [ { InstanceId => 'i-0xxxxx' } ], |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 DESCRIPTION |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Waiters are utility methods that poll for a particular state to occur on a client. Waiters can fail after a number of attempts at a polling interval defined for the service client. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 METHODS |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 GetWaiter |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $waiter = $service->GetWaiter('InstanceInService'); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This method returns a new PawsX::Waiter object and It has the following attributes. You can configure the waiter behaviour with this. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head3 delay(Int) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$waiter->delay(10); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Number of seconds to delay between polling attempts. Each waiter has a default delay configuration value, but you may need to modify this setting for specific use cases. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head3 maxAttempts(Int) |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$waiter->maxAttempts(100); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Maximum number of polling attempts to issue before failing the waiter. Each waiter has a default maxAttempts configuration value, |
94
|
|
|
|
|
|
|
but you may need to modify this setting for specific use cases. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head3 wait(HashRef) |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$waiter->wait( |
99
|
|
|
|
|
|
|
{ |
100
|
|
|
|
|
|
|
LoadBalancerName => 'test-elb', |
101
|
|
|
|
|
|
|
Instances => [ { InstanceId => 'i-0xxxxx' } ], |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Block until the waiter completes or fails.Note that this might throw a PawsX::Exception::* if the waiter fails. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SEE ALSO |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=over 4 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item L<Paws> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Prajith Ndz E<lt>prajithpalakkuda@gmail.comE<gt> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 COPYRIGHT |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Copyright (C) Prajith Ndz. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 LICENSE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
126
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |