line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package App::OverWatch::Notify; |
3
|
|
|
|
|
|
|
# ABSTRACT: Notify base class |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
2280
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
6
|
1
|
|
|
1
|
|
14
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
7
|
1
|
|
|
1
|
|
7
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
93
|
use App::OverWatch::DB; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use App::OverWatch::Notification; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Module::Load qw( load ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
|
|
|
|
|
|
my $class = shift; |
16
|
|
|
|
|
|
|
my $rh_options = shift || {}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $DB = $rh_options->{db} // die "Require 'db'"; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $type = $DB->type(); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $subclass = $class . '::' . $type; |
23
|
|
|
|
|
|
|
load($subclass); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $self = bless( {}, $subclass ); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$self->{DB} = $DB; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub create_notification { |
33
|
|
|
|
|
|
|
my $self = shift; |
34
|
|
|
|
|
|
|
my $rh_args = shift; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $system = $rh_args->{system} || die "Error: require 'system'"; |
37
|
|
|
|
|
|
|
my $subsystem = $rh_args->{subsystem} || die "Error: require 'subsystem'"; |
38
|
|
|
|
|
|
|
my $worker = $rh_args->{worker} || die "Error: require 'worker'"; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $sql =<<"SQL"; |
41
|
|
|
|
|
|
|
INSERT INTO |
42
|
|
|
|
|
|
|
notifications ( system, subsystem, worker, ctime, mtime ) |
43
|
|
|
|
|
|
|
VALUES |
44
|
|
|
|
|
|
|
( ?, ?, ?, NOW(), NOW() ) |
45
|
|
|
|
|
|
|
SQL |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $ret = $self->{DB}->dbix_run( $sql, $system, $subsystem, $worker ); |
48
|
|
|
|
|
|
|
return $ret; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub delete_notification { |
52
|
|
|
|
|
|
|
my $self = shift; |
53
|
|
|
|
|
|
|
my $rh_args = shift; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $system = $rh_args->{system} || die "Error: require 'system'"; |
56
|
|
|
|
|
|
|
my $subsystem = $rh_args->{subsystem} || die "Error: require 'subsystem'"; |
57
|
|
|
|
|
|
|
my $worker = $rh_args->{worker} || die "Error: require 'worker'"; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $sql =<<"SQL"; |
60
|
|
|
|
|
|
|
DELETE FROM |
61
|
|
|
|
|
|
|
notifications |
62
|
|
|
|
|
|
|
WHERE |
63
|
|
|
|
|
|
|
system = ? AND |
64
|
|
|
|
|
|
|
subsystem = ? AND |
65
|
|
|
|
|
|
|
worker = ? |
66
|
|
|
|
|
|
|
SQL |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $ret = $self->{DB}->dbix_run( $sql, $system, $subsystem, $worker ); |
69
|
|
|
|
|
|
|
return $ret; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub delete_all_notifications { |
73
|
|
|
|
|
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
my $rh_args = shift; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $worker = $rh_args->{worker} || die "Error: require 'worker'"; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $sql =<<"SQL"; |
79
|
|
|
|
|
|
|
DELETE FROM |
80
|
|
|
|
|
|
|
notifications |
81
|
|
|
|
|
|
|
WHERE |
82
|
|
|
|
|
|
|
worker = ? |
83
|
|
|
|
|
|
|
SQL |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $ret = $self->{DB}->dbix_run( $sql, $worker ); |
86
|
|
|
|
|
|
|
return $ret; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub check_notifications { |
90
|
|
|
|
|
|
|
my $self = shift; |
91
|
|
|
|
|
|
|
my $rh_args = shift; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $worker = $rh_args->{worker} || die "Error: require 'worker'"; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $sql =<<"SQL"; |
96
|
|
|
|
|
|
|
SELECT |
97
|
|
|
|
|
|
|
* |
98
|
|
|
|
|
|
|
FROM |
99
|
|
|
|
|
|
|
notifications |
100
|
|
|
|
|
|
|
WHERE |
101
|
|
|
|
|
|
|
worker = ? |
102
|
|
|
|
|
|
|
SQL |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $sth = $self->{DB}->dbix_select( $sql ); |
105
|
|
|
|
|
|
|
return undef if (!defined($sth)); |
106
|
|
|
|
|
|
|
my @notifications; |
107
|
|
|
|
|
|
|
while ( my $rh_row = $sth->fetchrow_hashref() ) { |
108
|
|
|
|
|
|
|
my $Notification = App::OverWatch::Notification->new($rh_row); |
109
|
|
|
|
|
|
|
push(@notifications, $Notification); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
return \@notifications; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub notify { |
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
my $rh_args = shift; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $system = $rh_args->{system} || die "Error: require 'system'"; |
119
|
|
|
|
|
|
|
my $subsystem = $rh_args->{subsystem} || die "Error: require 'subsystem'"; |
120
|
|
|
|
|
|
|
my $text = $rh_args->{text} || die "Error: require 'text'"; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my $sql =<<"SQL"; |
123
|
|
|
|
|
|
|
UPDATE |
124
|
|
|
|
|
|
|
notifications |
125
|
|
|
|
|
|
|
SET |
126
|
|
|
|
|
|
|
fired = 1, |
127
|
|
|
|
|
|
|
text = ?, |
128
|
|
|
|
|
|
|
mtime = NOW() |
129
|
|
|
|
|
|
|
WHERE |
130
|
|
|
|
|
|
|
system = ? AND |
131
|
|
|
|
|
|
|
subsystem = ? |
132
|
|
|
|
|
|
|
SQL |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $ret = $self->{DB}->dbix_run( $sql, $text, $system, $subsystem); |
135
|
|
|
|
|
|
|
return $ret; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |