… | |
… | |
55 | |
55 | |
56 | sub enabled() { |
56 | sub 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 | |
62 | Tells the supervisor to restart the process when it exits (enable |
62 | Tells the supervisor to restart the process when it exits (enable |
63 | autorestart), or forcefully after C<$timeout> seconds (minimum 1, maximum |
63 | autorestart), or forcefully after C<$timeout> seconds (minimum 1, maximum |
64 | 255, default 60). |
64 | 255, 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 | |
94 | Just like C<restart_in>, but also calls C<exit 0>. This means that this is |
94 | Just like C<restart_in>, but also calls C<exit 0>. This means that this is |
95 | the ideal method to force a restart. |
95 | the 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 | |
139 | Tells the supervisor to automatically kill the program if it doesn't |
139 | Tells the supervisor to automatically kill the program if it doesn't |
140 | react for C<$interval> seconds (minium 1, maximum 255, default 60) , then |
140 | react 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 | |
175 | Installs an exit hook that is executed when the program is about to exit, |
177 | Installs an exit hook that is executed when the program is about to exit, |
176 | while event processing is still active to some extent. |
178 | while event processing is still active to some extent. |
177 | |
179 | |
178 | The hook should do whatever it needs to do (close active connections, |
180 | The hook should do whatever it needs to do (close active connections, |