wahoo, created our first workflow and cron.

This commit is contained in:
JT Smith 2006-02-12 18:05:57 +00:00
parent c80902b65d
commit dc0ff0d1ed
6 changed files with 103 additions and 28 deletions

View file

@ -13,6 +13,8 @@ use strict;
use Getopt::Long; use Getopt::Long;
use WebGUI::Session; use WebGUI::Session;
use File::Path; use File::Path;
use WebGUI::Workflow;
use WebGUI::Workflow::Cron;
my $toVersion = "6.9.0"; # make this match what version you're going to my $toVersion = "6.9.0"; # make this match what version you're going to
my $quiet; # this line required my $quiet; # this line required
@ -68,7 +70,8 @@ sub addWorkflow {
workflowId varchar(22) binary not null primary key, workflowId varchar(22) binary not null primary key,
title varchar(255) not null default 'Untitled', title varchar(255) not null default 'Untitled',
description text, description text,
enabled int not null default 0 enabled int not null default 0,
type varchar(255) not null default 'none'
)"); )");
$session->db->write("create table WorkflowActivity ( $session->db->write("create table WorkflowActivity (
activityId varchar(22) binary not null primary key, activityId varchar(22) binary not null primary key,
@ -76,15 +79,32 @@ sub addWorkflow {
title varchar(255) not null default 'Untitled', title varchar(255) not null default 'Untitled',
description text, description text,
sequenceNumber int not null default 1, sequenceNumber int not null default 1,
dateCreated bigint,
className varchar(255) className varchar(255)
)"); )");
$session->db->write("create table WorkflowActivityProperty ( $session->db->write("create table WorkflowActivityData (
propertyId varchar(22) binary not null primary key,
activityId varchar(22) binary not null, activityId varchar(22) binary not null,
name varchar(255), name varchar(255) not null,
value text value text,
primary key (activityId, name)
)"); )");
my $workflow = WebGUI::Workflow->create($session, {
title=>"Clean Up Temp Files",
description=>"This workflow deletes temporary files from the WebGUI uploads folder.",
enabled=>1,
type=>"none"
}, "pbworkflow000000000001");
my $activity = $workflow->addActivity("WebGUI::Workflow::Activity::CleanTempStorage", "pbwfactivity0000000001");
$activity->set("title","Delete files older than 24 hours");
$activity->set("storageTimeout",60*60*24);
my $cron = WebGUI::Workflow::Cron->create($session, {
enabled=>1,
runOnce=>0,
minuteOfHour=>"30",
hourOfDay=>"23",
priority=>3,
workflowId=>$workflow->getId
}, "pbcron0000000000000001");
} }
#------------------------------------------------- #-------------------------------------------------

View file

@ -128,6 +128,7 @@ sub commit {
$self->unsetVersionLock; $self->unsetVersionLock;
$self->update({status=>'approved'}); $self->update({status=>'approved'});
$self->purgeCache; $self->purgeCache;
$self->indexContent;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -38,26 +38,33 @@ These methods are available from this class:
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 addActivity ( class ) =head2 addActivity ( class [, id ] )
Adds an activity to this workflow. Adds an activity to this workflow. Returns a reference to the new activity object.
=head3 class =head3 class
The classname of the activity to add. The classname of the activity to add.
=head3 id
Normally an ID will be generated for you, but if you want to override this and provide your own 22 character id, then you can specify it here.
=cut =cut
sub addActivity { sub addActivity {
my $self = shift; my $self = shift;
my $class = shift; my $class = shift;
$class->create($self->session, $self->getId); my $id = shift;
my $cmd = "use ".$class;
eval($cmd);
return $class->create($self->session, $self->getId, $id);
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 create ( session ) =head2 create ( session, properties, [, id ] )
Creates a new instance of a workflow. Creates a new instance of a workflow.
@ -65,13 +72,25 @@ Creates a new instance of a workflow.
A reference to the current session. A reference to the current session.
=head3 properties
A hash reference of properties to set for this workflow. See set() for details.
=head3 id
Normally an ID will be generated for you, but if you want to override this and provide your own 22 character id, then you can specify it here.
=cut =cut
sub create { sub create {
my $class = shift; my $class = shift;
my $session = shift; my $session = shift;
my $workflowId = $session->db->setRow("Workflow","workflowId",{workflowId=>"new",enabled=>0}); my $properties = shift;
return $class->new($session, $workflowId); my $id = shift;
my $workflowId = $session->db->setRow("Workflow","workflowId",{workflowId=>"new",enabled=>0},$id);
my $self = $class->new($session, $workflowId);
$self->set($properties);
return $self;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -109,6 +128,8 @@ sub deleteActivity {
my $self = shift; my $self = shift;
my $activityId = shift; my $activityId = shift;
my ($class) = $self->session->db->quickArray("select className from WorkflowActivity where activityId=?",[$activityId]); my ($class) = $self->session->db->quickArray("select className from WorkflowActivity where activityId=?",[$activityId]);
my $cmd = "use ".$class;
eval{$cmd};
$class->new($self->session, $activityId)->delete; $class->new($self->session, $activityId)->delete;
} }
@ -136,7 +157,8 @@ Returns the value for a given property.
sub get { sub get {
my $self = shift; my $self = shift;
return $self->{_data}{shift}; my $name = shift;
return $self->{_data}{$name};
} }
@ -154,6 +176,8 @@ sub getActivities {
my $rs = $self->session->db->prepare("select activityId, className from WorkflowActivity where workflowId=? order by sequenceNumber"); my $rs = $self->session->db->prepare("select activityId, className from WorkflowActivity where workflowId=? order by sequenceNumber");
$rs->execute([$self->getId]); $rs->execute([$self->getId]);
while (my ($activityId, $class) = $rs->array) { while (my ($activityId, $class) = $rs->array) {
my $cmd = "use ".$class;
eval{$cmd};
push(@activities, $class->new($self->session, $activityId)); push(@activities, $class->new($self->session, $activityId));
} }
return \@activities; return \@activities;
@ -181,6 +205,8 @@ sub getNextActivity {
and sequenceNumber>=? order by sequenceNumber", [$self->getId, $sequenceNumber]); and sequenceNumber>=? order by sequenceNumber", [$self->getId, $sequenceNumber]);
my ($id, $class) = $rs->array; my ($id, $class) = $rs->array;
$rs->finish; $rs->finish;
my $cmd = "use ".$class;
eval{$cmd};
return $class->new($self->session, $id); return $class->new($self->session, $id);
} }

View file

@ -39,7 +39,7 @@ These methods are available from this class:
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 create ( session, workflowId ) =head2 create ( session, workflowId [, id ] )
Creates a new instance of this activity in a workflow. Creates a new instance of this activity in a workflow.
@ -51,15 +51,25 @@ A reference to the current session.
The unique id of the workflow to attach this activity to. The unique id of the workflow to attach this activity to.
=head3 id
Normally an ID will be generated for you, but if you want to override this and provide your own 22 character id, then you can specify it here.
=cut =cut
sub create { sub create {
my $class = shift; my $class = shift;
my $session = shift; my $session = shift;
my $workflowId = shift; my $workflowId = shift;
my $id = shift;
my ($sequenceNumber) = $session->db->quickArray("select count(*) from WorkflowActivity where workflowId=?", [$workflowId]); my ($sequenceNumber) = $session->db->quickArray("select count(*) from WorkflowActivity where workflowId=?", [$workflowId]);
$sequenceNumber++; $sequenceNumber++;
my $activityId = $session->db->setRow("WorkflowActivity","activityId",{sequenceNumber=>$sequenceNumber, activityId=>"new", className=>$class, workflowId=>$workflowId}); my $activityId = $session->db->setRow("WorkflowActivity","activityId", {
sequenceNumber=>$sequenceNumber,
activityId=>"new",
className=>$class,
workflowId=>$workflowId
}, $id);
return $class->new($session, $activityId); return $class->new($session, $activityId);
} }
@ -121,7 +131,8 @@ Returns the value for a given property.
sub get { sub get {
my $self = shift; my $self = shift;
return $self->{_data}{shift}; my $name = shift;
return $self->{_data}{$name};
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -203,7 +214,7 @@ sub new {
my $activityId = shift; my $activityId = shift;
my $main = $session->db->getRow("WorkflowActivity","activityId", $activityId); my $main = $session->db->getRow("WorkflowActivity","activityId", $activityId);
return undef unless $main->{activityId}; return undef unless $main->{activityId};
my $sub = $session->db->buildHashRef("select name,value from WorkflowActivityData where activityId=".$session->db->quote($activityId)); my $sub = $session->db->buildHashRef("select name,value from WorkflowActivityData where activityId=?",[$activityId]);
my %data = (%{$main}, %{$sub}); my %data = (%{$main}, %{$sub});
bless {_session=>$session, _id=>$activityId, _data=>\%data}, $class; bless {_session=>$session, _id=>$activityId, _data=>\%data}, $class;
} }
@ -245,8 +256,8 @@ sub set {
if ($name eq "title" || $name eq "description") { if ($name eq "title" || $name eq "description") {
$self->session->db->setRow("WorkflowActivity","activityId",{ activityId=>$self->getId, title=>$self->get("title"), description=>$self->get("description")}); $self->session->db->setRow("WorkflowActivity","activityId",{ activityId=>$self->getId, title=>$self->get("title"), description=>$self->get("description")});
} else { } else {
my $sth = $self->session->db->prepare("replace into WorkflowActivitydata (activityId, name, value) values (?,?,?)"); my $sth = $self->session->db->prepare("replace into WorkflowActivityData (activityId, name, value) values (?,?,?)");
$sth->execute($self->getId, $name, $value); $sth->execute([$self->getId, $name, $value]);
} }
} }

View file

@ -39,7 +39,7 @@ These methods are available from this class:
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 create ( session, properties ) =head2 create ( session, properties [, id ] )
Creates a new scheduler job. Creates a new scheduler job.
@ -51,13 +51,18 @@ A reference to the current session.
The settable properties of the scheduler. See the set() method for details. The settable properties of the scheduler. See the set() method for details.
=head3 id
Normally an ID will be generated for you, but if you want to override this and provide your own 22 character id, then you can specify it here.
=cut =cut
sub create { sub create {
my $class = shift; my $class = shift;
my $session = shift; my $session = shift;
my $properties = shift; my $properties = shift;
my $taskId = $session->db->setRow("WorkflowSchedule","taskId",{taskId=>"new"}); my $id = shift;
my $taskId = $session->db->setRow("WorkflowSchedule","taskId",{taskId=>"new", enabled=>0, runOnce=>0}, $id);
my $self = $class->new($session, $taskId); my $self = $class->new($session, $taskId);
$self->set($properties); $self->set($properties);
return $self; return $self;
@ -102,7 +107,8 @@ Returns the value for a given property. See the set() method for details.
sub get { sub get {
my $self = shift; my $self = shift;
return $self->{_data}{shift}; my $name = shift;
return $self->{_data}{$name};
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -207,7 +213,7 @@ The unique ID of the workflow we should kick off when this cron matches.
The classname of an object that will be created to pass into the workflow. 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. The method name of the constructor for className.
@ -215,6 +221,10 @@ The method name of the constructor for className.
The parameters to be passed into the constructor. Note that the system will always pass in the session as the first argument. The parameters to be passed into the constructor. Note that the system will always pass in the session as the first argument.
=head4 priority
An integer between 1 and 3 that will represent what priority the workflow will run, 1 being highest and 3 being lowest. Defaults to 2.
=cut =cut
sub set { sub set {
@ -230,6 +240,7 @@ sub set {
} elsif ($properties->{runOnce} == 0) { } elsif ($properties->{runOnce} == 0) {
$self->{_data}{runOnce} = 0; $self->{_data}{runOnce} = 0;
} }
$self->{_data}{priority} = $properties->{priority} || $self->{_data}{priority} || 2;
$self->{_data}{minuteOfHour} = $properties->{minuteOfHour} || $self->{_data}{minuteOfHour} || 0; $self->{_data}{minuteOfHour} = $properties->{minuteOfHour} || $self->{_data}{minuteOfHour} || 0;
$self->{_data}{hourOfDay} = $properties->{hourOfDay} || $self->{_data}{hourOfDay} || "*"; $self->{_data}{hourOfDay} = $properties->{hourOfDay} || $self->{_data}{hourOfDay} || "*";
$self->{_data}{dayOfMonth} = $properties->{dayOfMonth} || $self->{_data}{dayOfMonth} || "*"; $self->{_data}{dayOfMonth} = $properties->{dayOfMonth} || $self->{_data}{dayOfMonth} || "*";
@ -237,9 +248,9 @@ sub set {
$self->{_data}{dayOfWeek} = $properties->{dayOfWeek} || $self->{_data}{dayOfWeek} || "*"; $self->{_data}{dayOfWeek} = $properties->{dayOfWeek} || $self->{_data}{dayOfWeek} || "*";
$self->{_data}{workflowId} = $properties->{workflowId} || $self->{_data}{workflowId}; $self->{_data}{workflowId} = $properties->{workflowId} || $self->{_data}{workflowId};
$self->{_data}{className} = (exists $properties->{className}) ? $properties->{className} : $self->{_data}{className}; $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}{parameters} = (exists $properties->{parameters}) ? $properties->{parameters} : $self->{_data}{parameters};
$self->{_data}{enabled} = 0 unless ($self->get("workflowId")); $self->{_data}{enabled} = 0 unless ($self->{_data}{workflowId});
my $spectre = WebGUI::Workflow::Spectre->new($self->session); my $spectre = WebGUI::Workflow::Spectre->new($self->session);
$self->session->db->setRow("WorkflowSchedule","taskId",$self->{_data}); $self->session->db->setRow("WorkflowSchedule","taskId",$self->{_data});
$spectre->notify("cron/deleteJob",$self->getId); $spectre->notify("cron/deleteJob",$self->getId);

View file

@ -39,7 +39,7 @@ These methods are available from this class:
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 create ( session, properties ) =head2 create ( session, properties [, id ] )
Creates a new workflow instance. Creates a new workflow instance.
@ -51,13 +51,18 @@ A reference to the current session.
The settable properties of the workflow instance. See the set() method for details. The settable properties of the workflow instance. See the set() method for details.
=head3 id
Normally an ID will be generated for you, but if you want to override this and provide your own 22 character id, then you can specify it here.
=cut =cut
sub create { sub create {
my $class = shift; my $class = shift;
my $session = shift; my $session = shift;
my $properties = shift; my $properties = shift;
my $instanceId = $session->db->setRow("WorkflowInstance","instanceId",{instanceId=>"new", runningSince=>time()}); my $id = shift;
my $instanceId = $session->db->setRow("WorkflowInstance","instanceId",{instanceId=>"new", runningSince=>time()}, $id);
my $self = $class->new($session, $instanceId); my $self = $class->new($session, $instanceId);
$self->set($properties); $self->set($properties);
return $self; return $self;
@ -102,7 +107,8 @@ Returns the value for a given property. See the set() method for details.
sub get { sub get {
my $self = shift; my $self = shift;
return $self->{_data}{shift}; my $name = shift;
return $self->{_data}{$name};
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------