- Removed the need for DateTime::Cron::Simple, which also added the ability

to use ! < and > in schedules.
This commit is contained in:
JT Smith 2006-09-30 19:29:47 +00:00
parent d995ff09fe
commit e22c679421
6 changed files with 66 additions and 20 deletions

View file

@ -16,7 +16,6 @@ package Spectre::Cron;
use strict;
use DateTime;
use DateTime::Cron::Simple;
use HTTP::Request::Common;
use HTTP::Cookies;
use POE qw(Component::Client::HTTP);
@ -160,8 +159,12 @@ A DateTime object representing the time to compare the schedule with.
sub checkSchedule {
my ($kernel, $self, $jobId, $now) = @_[KERNEL, OBJECT, ARG0, ARG1];
$self->debug("Checking schedule ".$jobId." against the current time.");
my $cron = DateTime::Cron::Simple->new($self->getJob($jobId)->{schedule});
if ($cron->validate_time($now)) {
my $job = $self->getJob($jobId);
if ($self->checkSegment($now->minute, $job->{minuteOfHour}, [0..59])
&& $self->checkSegment($now->hour, $job->{hourOfDay}, [0..23])
&& $self->checkSegment($now->day, $job->{dayOfMonth}, [1..31])
&& $self->checkSegment($now->month, $job->{monthOfYear}, [1..12])
&& $self->checkSegment($now->dow, $job->{dayOfWeek}, [0..6]) ) {
$self->debug("It's time to run ".$jobId.". Creating workflow instance.");
$kernel->yield("runJob",$jobId);
}
@ -187,6 +190,47 @@ sub checkSchedules {
#-------------------------------------------------------------------
=head2 checkSegment ( current, pattern, range )
Checks a crontab schedule segment against a current time segment.
=cut
sub checkSegment {
# borrowed from Set::Crontab on CPAN
my $self = shift;
my (@list, @and, @not);
my ($now, $spec, $range) = @_;
# 1,2-4,*/3,!13,>9,<15
foreach (split /,/, $spec) {
my @pick;
my $step = $1 if s#/(\d+)$##;
# 0+"01" == 1
if (/^(\d+)$/) { push @pick, 0+$1; }
elsif (/^\*$/) { push @pick, @$range; }
elsif (/^(\d+)-(\d+)$/) { push @pick, 0+$1..0+$2; }
elsif (/^!(\d+)$/) { push @not, "\$_ != 0+$1"; }
elsif (/^([<>])(\d+)$/) { push @and, "\$_ $1 0+$2"; }
if ($step) {
my $i;
@pick = grep { defined $_ if $i++ % $step == 0 } @pick;
}
push @list, @pick;
}
if (@and) {
my $and = join q{ && }, @and;
push @list, grep { defined $_ if eval $and } @$range;
}
if (@not) {
my $not = join q{ && }, @not;
@list = grep { defined $_ if eval $not } (@list ? @list : @$range);
}
my $matches = {map {$_ => 1} @list};
return exists $matches->{$now};
}
#-------------------------------------------------------------------
=head2 config
Returns a reference to the config object.

View file

@ -1,5 +1,5 @@
package WebGUI;
our $VERSION = "7.0.8";
our $VERSION = "7.0.9";
our $STATUS = "stable";
#-------------------------------------------------------------------

View file

@ -2,9 +2,9 @@ package WebGUI::i18n::English::Workflow_Cron;
our $I18N = {
'day of week help' => {
message => q|Which day of the week do you want this workflow triggered? The range is between 0 and 6 where 0 is Sunday. You can specify a specific day like "0" or "2". You can specify a range like "3-6". You may also specify all days of the week by "*". And finally you can specify a list of days of the week like "1,5,6".|,
message => q|Which day of the week do you want this workflow triggered? The range is between 0 and 6 where 0 is Sunday. You can specify a specific day like "0" or "2". You can specify a range like "3-6". You may also specify all days of the week by "*". You can also use &gt;3, &lt;3, or !3 to equate to greater than, less than, or not equal to 3 (or any number). And finally you can specify a list of days of the week like "1,5,6".|,
context => q|the hover help for the month of year field|,
lastUpdated => 0,
lastUpdated => 1159644012,
},
'day of week' => {
@ -14,9 +14,9 @@ our $I18N = {
},
'month of year help' => {
message => q|Which month of the year do you want this workflow triggered? The range is between 1 and 12. You can specify a specific month like "2" or 12". You can specify a range like "3-6". You may also specify all months by "*". You can specify intervals like "*/3" (every 3 months). And finally you can specify a list of months like "1,5,11".|,
message => q|Which month of the year do you want this workflow triggered? The range is between 1 and 12. You can specify a specific month like "2" or 12". You can specify a range like "3-6". You may also specify all months by "*". You can also use &gt;3, &lt;3, or !3 to equate to greater than, less than, or not equal to 3 (or any number). You can specify intervals like "*/3" (every 3 months). And finally you can specify a list of months like "1,5,11".|,
context => q|the hover help for the month of year field|,
lastUpdated => 1154368718,
lastUpdated => 1159644012,
},
'month of year' => {
@ -26,7 +26,7 @@ our $I18N = {
},
'day of month help' => {
message => q|Which day of the month do you want this workflow triggered? The range is between 1 and 31. You can specify a specific day like "2" or 12". You can specify a range like "3-6". You may also specify all days by "*". You can specify intervals like "*/3" (every 3 days). And finally you can specify a list of days like "1,5,11".|,
message => q|Which day of the month do you want this workflow triggered? The range is between 1 and 31. You can specify a specific day like "2" or 12". You can specify a range like "3-6". You may also specify all days by "*". You can specify intervals like "*/3" (every 3 days). You can also use &gt;3, &lt;3, or !3 to equate to greater than, less than, or not equal to 3 (or any number). And finally you can specify a list of days like "1,5,11".|,
context => q|the hover help for the day of month field|,
lastUpdated => 0,
},
@ -38,9 +38,9 @@ our $I18N = {
},
'hour of day help' => {
message => q|Which hour of the day do you want this workflow triggered? The range is between 0 and 23. You can specify a specific hour like "0" or 12". You may also specify all hours by "*". You can specify a range like "3-6". You can specify intervals like "*/3" (every 3 hours). And finally you can specify a list of hours like "1,5,17,21".|,
message => q|Which hour of the day do you want this workflow triggered? The range is between 0 and 23. You can specify a specific hour like "0" or 12". You may also specify all hours by "*". You can specify a range like "3-6". You can specify intervals like "*/3" (every 3 hours). You can also use &gt;3, &lt;3, or !3 to equate to greater than, less than, or not equal to 3 (or any number). And finally you can specify a list of hours like "1,5,17,21".|,
context => q|the hover help for the hour of day field|,
lastUpdated => 0,
lastUpdated => 1159644012,
},
'hour of day' => {
@ -50,9 +50,9 @@ our $I18N = {
},
'minute of hour help' => {
message => q|Which minute of the hour do you want this workflow triggered? The range is between 0 and 59. You can specify a specific minute like "0" or 12". You may also specify all minutes by "*". You can specify a range like "3-6". You can specify intervals like "*/3" (every 3 minutes). And finally you can specify a list of minutes like "1,5,17,24".|,
message => q|Which minute of the hour do you want this workflow triggered? The range is between 0 and 59. You can specify a specific minute like "0" or 12". You may also specify all minutes by "*". You can specify a range like "3-6". You can specify intervals like "*/3" (every 3 minutes). You can also use &gt;3, &lt;3, or !3 to equate to greater than, less than, or not equal to 3 (or any number). And finally you can specify a list of minutes like "1,5,17,24".|,
context => q|the hover help for the minute of hour field|,
lastUpdated => 0,
lastUpdated => 1159644012,
},
'minute of hour' => {