| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::EventStreamr::Status; |
|
2
|
2
|
|
|
2
|
|
1553
|
use Method::Signatures; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
15
|
|
|
3
|
2
|
|
|
2
|
|
2498
|
use JSON; |
|
|
2
|
|
|
|
|
37557
|
|
|
|
2
|
|
|
|
|
11
|
|
|
4
|
2
|
|
|
2
|
|
287
|
use Scalar::Util::Reftype; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
97
|
|
|
5
|
2
|
|
|
2
|
|
10
|
use Moo; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
19
|
|
|
6
|
2
|
|
|
2
|
|
599
|
use namespace::clean; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
17
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: A status object |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.5'; # VERSION: Generated by DZP::OurPkg:Version |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#my $ConfigRef = sub { |
|
14
|
|
|
|
|
|
|
# croak "config isn't a 'App::EventStreamr::Config' object!" unless reftype( $_[0] )->class eq "App::EventStreamr::Config"; |
|
15
|
|
|
|
|
|
|
#}; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'status' => ( is => 'rw' ); |
|
18
|
|
|
|
|
|
|
has 'config' => ( is => 'rw' ); |
|
19
|
|
|
|
|
|
|
|
|
20
|
2
|
50
|
|
2
|
|
290427
|
method starting($id,$type) { |
|
|
1
|
50
|
|
1
|
|
10
|
|
|
|
1
|
50
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
3
|
|
|
21
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
|
22
|
1
|
50
|
|
|
|
6
|
$self->{status}{$id}{runcount} = $self->{status}{$id}{runcount} ? $self->{status}{$id}{runcount} + 1 : 1; |
|
23
|
1
|
|
|
|
|
3
|
$self->{status}{$id}{running} = 0; |
|
24
|
1
|
|
|
|
|
2
|
$self->{status}{$id}{status} = "starting"; |
|
25
|
1
|
|
|
|
|
2
|
$self->{status}{$id}{state} = "soft"; |
|
26
|
1
|
|
|
|
|
3
|
$self->{status}{$id}{type} = $type; |
|
27
|
1
|
|
|
|
|
2
|
$self->{status}{$id}{id} = $id; |
|
28
|
1
|
|
|
|
|
6
|
$self->post_status(); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
2
|
0
|
|
2
|
|
6381
|
method waiting($id,$type,$status) { |
|
|
0
|
0
|
|
0
|
|
0
|
|
|
|
0
|
0
|
|
|
|
0
|
|
|
|
0
|
0
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
32
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
|
33
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{status} = $status; |
|
34
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{state} = "wait"; |
|
35
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{type} = $type; |
|
36
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{id} = $id; |
|
37
|
0
|
|
|
|
|
0
|
$self->post_status(); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
2
|
0
|
|
2
|
|
5138
|
method stopping($id,$type) { |
|
|
0
|
0
|
|
0
|
|
0
|
|
|
|
0
|
0
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
41
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
|
42
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{status} = "stopping"; |
|
43
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{state} = "soft"; |
|
44
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{type} = $type; |
|
45
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{id} = $id; |
|
46
|
0
|
|
|
|
|
0
|
$self->post_status(); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
2
|
0
|
|
2
|
|
4734
|
method restarting($id,$type) { |
|
|
0
|
0
|
|
0
|
|
0
|
|
|
|
0
|
0
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
50
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
|
51
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{status} = "restarting"; |
|
52
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{state} = "soft"; |
|
53
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{type} = $type; |
|
54
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{id} = $id; |
|
55
|
0
|
|
|
|
|
0
|
$self->post_status(); |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
2
|
50
|
|
2
|
|
5984
|
method set_state($state,$id,$type) { |
|
|
1
|
50
|
|
1
|
|
10
|
|
|
|
1
|
50
|
|
|
|
20
|
|
|
|
1
|
50
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
27
|
|
|
|
1
|
|
|
|
|
16
|
|
|
|
1
|
|
|
|
|
13
|
|
|
|
1
|
|
|
|
|
10
|
|
|
|
1
|
|
|
|
|
15
|
|
|
59
|
1
|
50
|
33
|
|
|
41
|
if (defined $self->{status}{$id}{running} && |
|
60
|
|
|
|
|
|
|
$self->{status}{$id}{running} != $state) { |
|
61
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
|
62
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{runcount} = 0; |
|
63
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{running} = $state; |
|
64
|
0
|
0
|
|
|
|
0
|
$self->{status}{$id}{status} = $state ? 'started' : 'stopped'; |
|
65
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{state} = "hard"; |
|
66
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{timestamp} = time; |
|
67
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{type} = $type; |
|
68
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{id} = $id; |
|
69
|
0
|
|
|
|
|
0
|
$self->post_status(); |
|
70
|
0
|
|
|
|
|
0
|
return 1; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
1
|
|
|
|
|
13
|
return 0; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
2
|
50
|
|
2
|
|
9840
|
method threshold($id,$type,$status = "failed") { |
|
|
1
|
50
|
|
1
|
|
531
|
|
|
|
1
|
50
|
|
|
|
5
|
|
|
|
1
|
50
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
3
|
|
|
76
|
1
|
50
|
|
|
|
11
|
$self->{status}{$id}{timestamp} = time if (! $self->{status}{$id}{timestamp}); |
|
77
|
1
|
|
|
|
|
5
|
my $age = time - $self->{status}{$id}{timestamp}; |
|
78
|
1
|
0
|
0
|
|
|
5
|
if ( defined $self->{status}{$id}{runcount} && |
|
|
|
|
33
|
|
|
|
|
|
79
|
|
|
|
|
|
|
($self->{status}{$id}{runcount} > 5 && (time % 10) != 0) ) { |
|
80
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{status} = $status; |
|
81
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{state} = "hard"; |
|
82
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{type} = $type; |
|
83
|
0
|
|
|
|
|
0
|
$self->{status}{$id}{id} = $id; |
|
84
|
0
|
|
|
|
|
0
|
$self->info("$id failed to start (count=".$self->{status}{$id}{runcount}.", died=$age secs ago)"); |
|
85
|
0
|
|
|
|
|
0
|
$self->post_status(); |
|
86
|
0
|
|
|
|
|
0
|
return 1; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
1
|
|
|
|
|
6
|
return 0; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
2
|
50
|
|
2
|
|
1704
|
method post_status { |
|
|
1
|
|
|
1
|
|
2
|
|
|
|
1
|
|
|
|
|
4
|
|
|
92
|
1
|
50
|
|
|
|
13
|
if ($self->config) { |
|
93
|
0
|
|
|
|
|
|
my $status; |
|
94
|
0
|
|
|
|
|
|
$status->{status} = $self->{status}; |
|
95
|
0
|
|
|
|
|
|
$status->{macaddress} = $self->config->macaddress; |
|
96
|
0
|
|
|
|
|
|
$status->{nickname} = $self->config->nickname; |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $json = to_json($status); |
|
99
|
0
|
|
|
|
|
|
my %post_data = ( |
|
100
|
|
|
|
|
|
|
content => $json, |
|
101
|
|
|
|
|
|
|
'content-type' => 'application/json', |
|
102
|
|
|
|
|
|
|
'content-length' => length($json), |
|
103
|
|
|
|
|
|
|
); |
|
104
|
|
|
|
|
|
|
my $post = $self->config->http->post( |
|
105
|
0
|
|
|
|
|
|
"http://".$self->config->{mixer}{host}.":3000/status/".$self->config->macaddress, |
|
106
|
|
|
|
|
|
|
\%post_data, |
|
107
|
|
|
|
|
|
|
); |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$self->debug("Status posted to http://".$self->config->{mixer}{host}.":3000/status/".$self->config->macaddress); |
|
110
|
0
|
0
|
|
|
|
|
$self->debug({filter => \&Data::Dumper::Dumper, |
|
111
|
|
|
|
|
|
|
value => $post}) if ($self->is_debug()); |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
if ( $self->config->controller ) { |
|
114
|
|
|
|
|
|
|
# The Frontend doesn't like empty objects.. |
|
115
|
|
|
|
|
|
|
# TODO: Fix the frontend |
|
116
|
0
|
|
|
|
|
|
foreach my $key (keys %{$self->{status}}) { |
|
|
0
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if (! defined $self->{status}{$key}{id}) { |
|
118
|
0
|
|
|
|
|
|
delete $self->{status}{$key}; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $data; |
|
123
|
0
|
|
|
|
|
|
$data->{key} = "status"; |
|
124
|
0
|
|
|
|
|
|
$data->{value} = $self->{status}; |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
%post_data = ( |
|
127
|
|
|
|
|
|
|
content => to_json($data), |
|
128
|
|
|
|
|
|
|
headers => { |
|
129
|
|
|
|
|
|
|
'station-mgr' => 1, |
|
130
|
|
|
|
|
|
|
'Content-Type' => 'application/json', |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
); |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$post = $self->config->http->post( |
|
135
|
|
|
|
|
|
|
$self->config->controller."/api/station/".$self->config->macaddress."/partial", |
|
136
|
|
|
|
|
|
|
\%post_data, |
|
137
|
|
|
|
|
|
|
); |
|
138
|
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
$self->debug({filter => \&Data::Dumper::Dumper, |
|
140
|
|
|
|
|
|
|
value => $post}) if ($self->is_debug()); |
|
141
|
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
$self->info("Status posted to ".$self->config->controller."/api/station/".$self->config->macaddress."/partial"); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
with('App::EventStreamr::Roles::Logger'); |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
__END__ |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=pod |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=encoding UTF-8 |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 NAME |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
App::EventStreamr::Status - A status object |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 VERSION |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
version 0.5 |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
This package provides core status notification methods. |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Whilst at it's core EventStreamr Starts/Stops processes, the ability |
|
172
|
|
|
|
|
|
|
to notify when something goes wrong and can't be fixed by itself is |
|
173
|
|
|
|
|
|
|
the primary job. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
It provides some convenience methods to keep the Run/Stop code nice |
|
176
|
|
|
|
|
|
|
and simple. It also is intended to be passed around as a reference |
|
177
|
|
|
|
|
|
|
to ensure state is maintained across the application. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 AUTHOR |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Leon Wright < techman@cpan.org > |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This software is Copyright (c) 2014 by Leon Wright. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This is free software, licensed under: |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
The GNU Affero General Public License, Version 3, November 2007 |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=cut |