more workflow stuff
This commit is contained in:
parent
d9ae5745a5
commit
ec5193e5d3
8 changed files with 676 additions and 10 deletions
|
|
@ -57,7 +57,9 @@ sub create {
|
|||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $workflowId = shift;
|
||||
my $activityId = $session->db->setRow("WorkflowActivity","activityId",{activityId=>"new", workflowId=>$workflowId});
|
||||
my ($sequenceNumber) = $session->db->quickArray("select count(*) from WorkflowActivity where workflowId=?", [$workflowId]);
|
||||
$sequenceNumber++;
|
||||
my $activityId = $session->db->setRow("WorkflowActivity","activityId",{sequenceNumber=>$sequenceNumber, activityId=>"new", className=>$class, workflowId=>$workflowId});
|
||||
return $class->new($session, $activityId);
|
||||
}
|
||||
|
||||
|
|
@ -72,8 +74,9 @@ Removes this activity from its workflow.
|
|||
sub delete {
|
||||
my $self = shift;
|
||||
my $sth = $self->session->db->prepare("delete from WorkflowActivityData where activityId=?");
|
||||
$sth->execute($self->getId);
|
||||
$sth->execute([$self->getId]);
|
||||
$self->session->db->deleteRow("WorkflowActivity","activityId",$self->getId);
|
||||
undef $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
252
lib/WebGUI/Workflow/Cron.pm
Normal file
252
lib/WebGUI/Workflow/Cron.pm
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
package WebGUI::Workflow::Cron;
|
||||
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2006 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use WebGUI::Workflow::Spectre;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Workflow::Cron
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This package provides an API for controlling Spectre/Workflow scheduler activities.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Workflow::Cron
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 create ( session, properties )
|
||||
|
||||
Creates a new scheduler job.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 properties
|
||||
|
||||
The settable properties of the scheduler. See the set() method for details.
|
||||
|
||||
=cut
|
||||
|
||||
sub create {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $properties = shift;
|
||||
my $taskId = $session->db->setRow("WorkflowSchedule","taskId",{taskId=>"new"});
|
||||
my $self = $class->new($session, $taskId);
|
||||
$self->set($properties);
|
||||
return $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 delete ( )
|
||||
|
||||
Removes this job from the schedule.
|
||||
|
||||
=cut
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
$self->session->db->deleteRow("WorkflowSchedule","taskId",$self->getId);
|
||||
WebGUI::Workflow::Spectre->new($self->session)->notify("cron/deleteJob",$self->getId);
|
||||
undef $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 DESTROY ( )
|
||||
|
||||
Deconstructor.
|
||||
|
||||
=cut
|
||||
|
||||
sub DESTROY {
|
||||
my $self = shift;
|
||||
undef $self;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 get ( name )
|
||||
|
||||
Returns the value for a given property.
|
||||
|
||||
=cut
|
||||
|
||||
sub get {
|
||||
my $self = shift;
|
||||
return $self->{_data}{shift};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getId ( )
|
||||
|
||||
Returns the ID of this instance.
|
||||
|
||||
=cut
|
||||
|
||||
sub getId {
|
||||
my $self = shift;
|
||||
return $self->{_id};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session, taskId )
|
||||
|
||||
Constructor.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 taskId
|
||||
|
||||
A unique id refering to a task.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
my $taskId = shift;
|
||||
my $data = $session->db->getRow("WorkflowSchedule","taskId", $taskId);
|
||||
return undef unless $data->{taskId};
|
||||
bless {_session=>$session, _id=>$taskId, _data=>$data}, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
Returns a reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 set ( properties )
|
||||
|
||||
Sets one or more of the properties of this task.
|
||||
|
||||
=head3 properties
|
||||
|
||||
A hash reference containing properties to change.
|
||||
|
||||
=head4 enabled
|
||||
|
||||
A boolean indicating whether this task is enabled.
|
||||
|
||||
=head4 runOnce
|
||||
|
||||
A boolean indicating whether this task should run once and delete itself, or if it should continue to be executed each time it's schedule matches the current time.
|
||||
|
||||
=head4 minuteOfHour
|
||||
|
||||
A string in cron format representing which minutes (0-59) of the hour this workflow should run. Valid formats are as follows:
|
||||
|
||||
* All
|
||||
n A specific minute
|
||||
n,n,n A series of specific minutes
|
||||
*/n Every n minutes
|
||||
|
||||
=head4 hourOfDay
|
||||
|
||||
A string representing hours (0-23). See minuteOfHour for formatting details.
|
||||
|
||||
=head4 dayOfMonth
|
||||
|
||||
A string representing days in a month (1-31). See minuteOfHour for formatting details.
|
||||
|
||||
=head4 monthOfYear
|
||||
|
||||
A string representing months in a year (1-12). See minuteOfHour for formatting details.
|
||||
|
||||
=head4 dayOfWeek
|
||||
|
||||
A string representing days in a week (0-6 with Sunday being 0). See minuteOfHour for formatting details.
|
||||
|
||||
=head4 workflowId
|
||||
|
||||
The unique ID of the workflow we should kick off when this cron matches.
|
||||
|
||||
=head4 className
|
||||
|
||||
The classname of an object that will be created to pass into the workflow.
|
||||
|
||||
=head4 method
|
||||
|
||||
The method name of the constructor for className.
|
||||
|
||||
=head4 parameters
|
||||
|
||||
The parameters to be passed into the constructor. Note that the system will always pass in the session as the first argument.
|
||||
|
||||
=cut
|
||||
|
||||
sub set {
|
||||
my $self = shift;
|
||||
my $properties = shift;
|
||||
if ($properties->{enabled} == 1) {
|
||||
$self->{enabled} = 1;
|
||||
} elsif ($properties->{enabled} == 0) {
|
||||
$self->{enabled} = 0;
|
||||
}
|
||||
if ($properties->{runOnce} == 1) {
|
||||
$self->{runOnce} = 1;
|
||||
} elsif ($properties->{runOnce} == 0) {
|
||||
$self->{runOnce} = 0;
|
||||
}
|
||||
$self->{_data}{minuteOfHour} = $properties->{minuteOfHour} || $self->{_data}{minuteOfHour} || 0;
|
||||
$self->{_data}{hourOfDay} = $properties->{hourOfDay} || $self->{_data}{hourOfDay} || "*";
|
||||
$self->{_data}{dayOfMonth} = $properties->{dayOfMonth} || $self->{_data}{dayOfMonth} || "*";
|
||||
$self->{_data}{monthOfYear} = $properties->{monthOfYear} || $self->{_data}{monthOfYear} || "*";
|
||||
$self->{_data}{dayOfWeek} = $properties->{dayOfWeek} || $self->{_data}{dayOfWeek} || "*";
|
||||
$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}{parameters} = (exists $properties->{parameters}) ? $properties->{parameters} : $self->{_data}{parameters};
|
||||
$self->{_data}{enabled} = 0 unless ($self->get("workflowId"));
|
||||
my $spectre = WebGUI::Workflow::Spectre->new($self->session);
|
||||
$spectre->notify("cron/deleteJob",$self->getId);
|
||||
$spectre->notify("cron/addJob",$self->session->config->getFilename, $self->getId);
|
||||
$self->session->db->setRow("WorkflowSchedule","taskId",$self->{_data});
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
126
lib/WebGUI/Workflow/Spectre.pm
Normal file
126
lib/WebGUI/Workflow/Spectre.pm
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
package WebGUI::Workflow::Spectre;
|
||||
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2006 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use POE::Component::IKC::ClientLite;
|
||||
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Workflow::Spectre
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This package is used to send messages between the workflow system and Spectre.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Workflow::Spectre;
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 DESTROY ( )
|
||||
|
||||
Deconstructor.
|
||||
|
||||
=cut
|
||||
|
||||
sub DESTROY {
|
||||
my $self = shift;
|
||||
undef $self;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 notify ( module, params )
|
||||
|
||||
Sends a message to Spectre.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=head3 module
|
||||
|
||||
The module/method pair you wish to communicate with in Spectre.
|
||||
|
||||
=head3 params
|
||||
|
||||
An array of the parameters to send.
|
||||
|
||||
=cut
|
||||
|
||||
sub notify {
|
||||
my $self = shift;
|
||||
my $module = shift;
|
||||
my @params = @_;
|
||||
my $remote = create_ikc_client(
|
||||
port=>$self->session->config->get("spectrePort"),
|
||||
ip=>$self->session->config->get("spectreIp"),
|
||||
name=>rand(100000),
|
||||
timeout=>10
|
||||
);
|
||||
if ($remote) {
|
||||
my $result = $remote->post('admin/shutdown', @params);
|
||||
unless (defined $result) {
|
||||
$self->session->errorHandler->warn("Couldn't send command to Spectre because ".$POE::Component::IKC::ClientLite::error);
|
||||
}
|
||||
undef $remote;
|
||||
} else {
|
||||
$self->session->errorHandler->warn("Couldn't connect to Spectre because ".$POE::Component::IKC::ClientLite::error);
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 new ( session )
|
||||
|
||||
Constructor.
|
||||
|
||||
=head3 session
|
||||
|
||||
A reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
bless {_session=>$session}, $class;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 session ( )
|
||||
|
||||
Returns a reference to the current session.
|
||||
|
||||
=cut
|
||||
|
||||
sub session {
|
||||
my $self = shift;
|
||||
return $self->{_session};
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue