wahoo...cron works

This commit is contained in:
JT Smith 2006-02-12 19:02:38 +00:00
parent dc0ff0d1ed
commit 80288a38b2
3 changed files with 23 additions and 7 deletions

View file

@ -44,7 +44,7 @@ sub addWorkflow {
taskId varchar(22) binary not null primary key,
enabled int not null default 0,
runOnce int not null default 0,
minuteofHour varchar(25) not null default '0',
minuteOfHour varchar(25) not null default '0',
hourOfDay varchar(25) not null default '*',
dayOfMonth varchar(25) not null default '*',
monthOfYear varchar(25) not null default '*',

View file

@ -19,6 +19,8 @@ use DateTime;
use DateTime::Cron::Simple;
use POE;
use WebGUI::Session;
use WebGUI::Workflow::Cron;
use WebGUI::Workflow::Instance;
#-------------------------------------------------------------------
@ -82,7 +84,12 @@ sub addJob {
jobId=>$job->{jobId},
config=>$config,
schedule=>join(" ", $job->{minuteOfHour}, $job->{hourOfDay}, $job->{dayOfMonth}, $job->{monthOfYear}, $job->{dayOfWeek}),
workflowId=>$job->{workflowId}
runOnce=>$job->{runOnce},
workflowId=>$job->{workflowId},
className=>$job->{className},
methodName=>$job->{methodName},
parameters=>$job->{parameters},
priority=>$job->{priority}
}
}
@ -107,7 +114,15 @@ sub checkSchedule {
my ($kernel, $self, $job, $now) = @_[KERNEL, OBJECT, ARG0, ARG1];
my $cron = DateTime::Cron::Simple->new($job->{schedule});
if ($cron->validate_time($now)) {
# kick off an event here once we know what that api looks like
my $session = WebGUI::Session->open($self->{_config}->getWebguiRoot, $job->{config});
my $instance = WebGUI::Workflow::Instance->create($session, {
workflowId=>$job->{workflowId},
className=>$job->{className},
methodName=>$job->{methodName},
parameters=>$job->{parameters},
priority=>$job->{priority}
});
$session->close;
}
}
@ -125,6 +140,7 @@ sub checkSchedules {
foreach my $jobId (keys %{$self->{_jobs}}) {
$kernel->yield("checkSchedule", $self->{_jobs}{$jobId}, $now)
}
$kernel->delay_set("checkSchedules",60);
}

View file

@ -171,8 +171,8 @@ sub run {
return "complete" unless (defined $activity);
my $object = {};
my $class = $self->get("className");
my $method = $self->get("method");
my $params = $self->get("params");
my $method = $self->get("methodName");
my $params = $self->get("parameters");
if ($class && $method) {
$params = eval($params);
if ($@) {
@ -224,7 +224,7 @@ The id of the workflow we're executing.
The classname of an object that will be created to pass into the workflow.
=head4 method
=head4 methodName
The method name of the constructor for className.
@ -244,7 +244,7 @@ sub set {
$self->{_data}{priority} = $properties->{priority} || $self->{_data}{priority} || 2;
$self->{_data}{workflowId} = $properties->{workflowId} || $self->{_data}{workflowId};
$self->{_data}{className} = (exists $properties->{className}) ? $properties->{className} : $self->{_data}{className};
$self->{_data}{method} = (exists $properties->{method}) ? $properties->{method} : $self->{_data}{method};
$self->{_data}{methodName} = (exists $properties->{methodName}) ? $properties->{methodName} : $self->{_data}{methodName};
$self->{_data}{parameters} = (exists $properties->{parameters}) ? $properties->{parameters} : $self->{_data}{parameters};
$self->{_data}{currentActivityId} = (exists $properties->{currentActivityId}) ? $properties->{currentActivityId} : $self->{_data}{currentActivityId};
$self->{_data}{lastUpdate} = time();