line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::EventStreamr::Status; |
2
|
3
|
|
|
3
|
|
1495
|
use Method::Signatures; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
22
|
|
3
|
3
|
|
|
3
|
|
1982
|
use JSON; |
|
3
|
|
|
|
|
17759
|
|
|
3
|
|
|
|
|
15
|
|
4
|
3
|
|
|
3
|
|
761
|
use Scalar::Util::Reftype; |
|
3
|
|
|
|
|
1939
|
|
|
3
|
|
|
|
|
145
|
|
5
|
3
|
|
|
3
|
|
13
|
use Moo; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
25
|
|
6
|
3
|
|
|
3
|
|
780
|
use namespace::clean; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
22
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: A status object |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.4'; # 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
|
3
|
0
|
|
3
|
|
8131
|
method starting($id,$type) { |
|
0
|
0
|
|
0
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
22
|
0
|
0
|
|
|
|
|
$self->{status}{$id}{runcount} = $self->{status}{$id}{runcount} ? $self->{status}{$id}{runcount} + 1 : 1; |
23
|
0
|
|
|
|
|
|
$self->{status}{$id}{running} = 0; |
24
|
0
|
|
|
|
|
|
$self->{status}{$id}{status} = "starting"; |
25
|
0
|
|
|
|
|
|
$self->{status}{$id}{state} = "soft"; |
26
|
0
|
|
|
|
|
|
$self->{status}{$id}{type} = $type; |
27
|
0
|
|
|
|
|
|
$self->{status}{$id}{id} = $id; |
28
|
0
|
|
|
|
|
|
$self->post_status(); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
3
|
0
|
|
3
|
|
6897
|
method waiting($id,$type,$status) { |
|
0
|
0
|
|
0
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
33
|
0
|
|
|
|
|
|
$self->{status}{$id}{status} = $status; |
34
|
0
|
|
|
|
|
|
$self->{status}{$id}{state} = "wait"; |
35
|
0
|
|
|
|
|
|
$self->{status}{$id}{type} = $type; |
36
|
0
|
|
|
|
|
|
$self->{status}{$id}{id} = $id; |
37
|
0
|
|
|
|
|
|
$self->post_status(); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
3
|
0
|
|
3
|
|
5565
|
method stopping($id,$type) { |
|
0
|
0
|
|
0
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
42
|
0
|
|
|
|
|
|
$self->{status}{$id}{status} = "stopping"; |
43
|
0
|
|
|
|
|
|
$self->{status}{$id}{state} = "soft"; |
44
|
0
|
|
|
|
|
|
$self->{status}{$id}{type} = $type; |
45
|
0
|
|
|
|
|
|
$self->{status}{$id}{id} = $id; |
46
|
0
|
|
|
|
|
|
$self->post_status(); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
3
|
0
|
|
3
|
|
5739
|
method restarting($id,$type) { |
|
0
|
0
|
|
0
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
51
|
0
|
|
|
|
|
|
$self->{status}{$id}{status} = "restarting"; |
52
|
0
|
|
|
|
|
|
$self->{status}{$id}{state} = "soft"; |
53
|
0
|
|
|
|
|
|
$self->{status}{$id}{type} = $type; |
54
|
0
|
|
|
|
|
|
$self->{status}{$id}{id} = $id; |
55
|
0
|
|
|
|
|
|
$self->post_status(); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
3
|
0
|
|
3
|
|
7620
|
method set_state($state,$id,$type) { |
|
0
|
0
|
|
0
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
59
|
0
|
0
|
0
|
|
|
|
if (defined $self->{status}{$id}{running} && |
60
|
|
|
|
|
|
|
$self->{status}{$id}{running} != $state) { |
61
|
|
|
|
|
|
|
# TODO: Logging here once log role exists |
62
|
0
|
|
|
|
|
|
$self->{status}{$id}{runcount} = 0; |
63
|
0
|
|
|
|
|
|
$self->{status}{$id}{running} = $state; |
64
|
0
|
0
|
|
|
|
|
$self->{status}{$id}{status} = $state ? 'started' : 'stopped'; |
65
|
0
|
|
|
|
|
|
$self->{status}{$id}{state} = "hard"; |
66
|
0
|
|
|
|
|
|
$self->{status}{$id}{timestamp} = time; |
67
|
0
|
|
|
|
|
|
$self->{status}{$id}{type} = $type; |
68
|
0
|
|
|
|
|
|
$self->{status}{$id}{id} = $id; |
69
|
0
|
|
|
|
|
|
$self->post_status(); |
70
|
0
|
|
|
|
|
|
return 1; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
return 0; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
3
|
0
|
|
3
|
|
12201
|
method threshold($id,$type,$status = "failed") { |
|
0
|
0
|
|
0
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
$self->{status}{$id}{timestamp} = time if (! $self->{status}{$id}{timestamp}); |
77
|
0
|
|
|
|
|
|
my $age = time - $self->{status}{$id}{timestamp}; |
78
|
0
|
0
|
0
|
|
|
|
if ( defined $self->{status}{$id}{runcount} && |
|
|
|
0
|
|
|
|
|
79
|
|
|
|
|
|
|
($self->{status}{$id}{runcount} > 5 && (time % 10) != 0) ) { |
80
|
0
|
|
|
|
|
|
$self->{status}{$id}{status} = $status; |
81
|
0
|
|
|
|
|
|
$self->{status}{$id}{state} = "hard"; |
82
|
0
|
|
|
|
|
|
$self->{status}{$id}{type} = $type; |
83
|
0
|
|
|
|
|
|
$self->{status}{$id}{id} = $id; |
84
|
0
|
|
|
|
|
|
$self->info("$id failed to start (count=".$self->{status}{$id}{runcount}.", died=$age secs ago)"); |
85
|
0
|
|
|
|
|
|
$self->post_status(); |
86
|
0
|
|
|
|
|
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
0
|
|
|
|
|
|
return 0; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
3
|
0
|
|
3
|
|
2034
|
method post_status { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
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
|
0
|
|
|
|
|
|
my $post = $self->config->http->post( |
105
|
|
|
|
|
|
|
"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.4 |
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 |