ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-Watchdog/Watchdog/Util.pm
(Generate patch)

Comparing AnyEvent-Watchdog/Watchdog/Util.pm (file contents):
Revision 1.3 by root, Tue Sep 1 16:30:47 2009 UTC vs.
Revision 1.5 by root, Wed Sep 2 14:02:32 2009 UTC

55 55
56sub enabled() { 56sub enabled() {
57 $AnyEvent::Watchdog::ENABLED 57 $AnyEvent::Watchdog::ENABLED
58} 58}
59 59
60=item AnyEvent::Watchdog::restart_in [$timeout] 60=item AnyEvent::Watchdog::Util::restart_in [$timeout]
61 61
62Tells the supervisor to restart the process when it exits (enable 62Tells the supervisor to restart the process when it exits (enable
63autorestart), or forcefully after C<$timeout> seconds (minimum 1, maximum 63autorestart), or forcefully after C<$timeout> seconds (minimum 1, maximum
64255, default 60). 64255, default 60).
65 65
87 87
88 # now make sure we dont' send it any further requests 88 # now make sure we dont' send it any further requests
89 our $OLD_C = $C; undef $C; 89 our $OLD_C = $C; undef $C;
90} 90}
91 91
92=item AnyEvent::Watchdog::restart [$timeout] 92=item AnyEvent::Watchdog::Util::restart [$timeout]
93 93
94Just like C<restart_in>, but also calls C<exit 0>. This means that this is 94Just like C<restart_in>, but also calls C<exit 0>. This means that this is
95the ideal method to force a restart. 95the ideal method to force a restart.
96 96
97=cut 97=cut
130 } 130 }
131 131
132 syswrite $C, $AUTORESTART ? "\x01" : "\x00"; 132 syswrite $C, $AUTORESTART ? "\x01" : "\x00";
133} 133}
134 134
135=item AnyEvent::Watchdog::heartbeat [$interval] 135=item AnyEvent::Watchdog::Util::heartbeat [$interval]
136 136
137=item use AnyEvent::Watchdog heartbeat => $interval 137=item use AnyEvent::Watchdog heartbeat => $interval
138 138
139Tells the supervisor to automatically kill the program if it doesn't 139Tells the supervisor to automatically kill the program if it doesn't
140react for C<$interval> seconds (minium 1, maximum 255, default 60) , then 140react for C<$interval> seconds (minium 1, maximum 255, default 60) , then
159 159
160 $interval = 60 unless defined $interval; 160 $interval = 60 unless defined $interval;
161 $interval = 0 if $interval < 0; 161 $interval = 0 if $interval < 0;
162 $interval = 255 if $interval > 255; 162 $interval = 255 if $interval > 255;
163 163
164 $interval = int $interval;
165
164 syswrite $C, "\x03" . chr int $interval 166 syswrite $C, "\x03" . chr $interval
165 if $C; 167 if $C;
166 168
167 $HEARTBEAT_W = $interval && AE::timer (0, $interval * 0.5, sub { 169 $HEARTBEAT_W = AE::timer 0, $interval * 0.5, sub {
168 syswrite $C, "\x04" 170 syswrite $C, "\x04"
169 if $C; 171 if $C;
170 }); 172 };
171} 173}
172 174
173=item AnyEvent::Watchdog::on_exit { BLOCK; shift->() } 175=item AnyEvent::Watchdog::Util::on_exit { BLOCK; shift->() }
174 176
175Installs an exit hook that is executed when the program is about to exit, 177Installs an exit hook that is executed when the program is about to exit,
176while event processing is still active to some extent. 178while event processing is still active to some extent.
177 179
178The hook should do whatever it needs to do (close active connections, 180The hook should do whatever it needs to do (close active connections,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines