| 1 | ## | ||||||||||
| 2 | ## Load Average Constraint | ||||||||||
| 3 | ## Author: Vipul Ved Prakash <mail@vipul.net>. | ||||||||||
| 4 | ## $Id: Freq.pm,v 1.6 2005/04/26 07:31:08 hackworth Exp $ | ||||||||||
| 5 | ## | ||||||||||
| 6 | |||||||||||
| 7 | package Schedule::Chronic::Constraint::Freq; | ||||||||||
| 8 | 1 | ▶ | use Schedule::Chronic::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use base qw(Schedule::Chronic::Base); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | # NOTE: This module overloads the concept of wait to store the number of | ||||||||||
| 12 | # seconds left before execution. Don't let this confuse you, | ||||||||||
| 13 | # specially if you are looking at this as a an example for your | ||||||||||
| 14 | # constraint module. | ||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 18 | 0 | return bless {}, shift; | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | 0 | ▶ | sub init { | ||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 23 | |||||||||||
| 24 | 0 | my ($self, $schedule, $task, $logger, $seconds) = @_; | |||||||||
| 25 | |||||||||||
| 26 | # @args can be: | ||||||||||
| 27 | # 86400 | ||||||||||
| 28 | # 86400, Force | ||||||||||
| 29 | # Force is not implemented | ||||||||||
| 30 | |||||||||||
| 31 | 0 | $$self{schedule} = $schedule; | |||||||||
| 32 | 0 | $$self{task} = $task; | |||||||||
| 33 | 0 | $$self{logger} = $logger; | |||||||||
| 34 | |||||||||||
| 35 | 0 | $$self{seconds} = $seconds; | |||||||||
| 36 | 0 | $$self{wait} = 0; | |||||||||
| 37 | |||||||||||
| 38 | 0 | return $self; | |||||||||
| 39 | |||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | |||||||||||
| 43 | 0 | ▶ | sub met { | ||||||||
|
Subroutine
met: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 44 | |||||||||||
| 45 | 0 | my ($self) = @_; | |||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | return 1 if $$self{task}{last_ran} == 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | 0 | $$self{wait} = $$self{task}{last_ran} - (time() - $$self{seconds}); | |||||||||
| 49 | 0 | $self->debug(" freq wait = $$self{wait} seconds"); | |||||||||
| 50 | 0 | ▶ | return 1 if ($$self{wait} < 0); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | return 0; | |||||||||
| 52 | |||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub wait { | ||||||||
|
Subroutine
wait: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 57 | |||||||||||
| 58 | 0 | return $_[0]->{wait}; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | |||||||||||
| 62 | 1 | 1; | |||||||||
| 63 | |||||||||||