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

@ -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.
@ -51,15 +51,25 @@ A reference to the current session.
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
sub create {
my $class = shift;
my $session = shift;
my $workflowId = shift;
my $id = shift;
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});
my $activityId = $session->db->setRow("WorkflowActivity","activityId", {
sequenceNumber=>$sequenceNumber,
activityId=>"new",
className=>$class,
workflowId=>$workflowId
}, $id);
return $class->new($session, $activityId);
}
@ -121,7 +131,8 @@ Returns the value for a given property.
sub get {
my $self = shift;
return $self->{_data}{shift};
my $name = shift;
return $self->{_data}{$name};
}
#-------------------------------------------------------------------
@ -203,7 +214,7 @@ sub new {
my $activityId = shift;
my $main = $session->db->getRow("WorkflowActivity","activityId", $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});
bless {_session=>$session, _id=>$activityId, _data=>\%data}, $class;
}
@ -245,8 +256,8 @@ sub set {
if ($name eq "title" || $name eq "description") {
$self->session->db->setRow("WorkflowActivity","activityId",{ activityId=>$self->getId, title=>$self->get("title"), description=>$self->get("description")});
} else {
my $sth = $self->session->db->prepare("replace into WorkflowActivitydata (activityId, name, value) values (?,?,?)");
$sth->execute($self->getId, $name, $value);
my $sth = $self->session->db->prepare("replace into WorkflowActivityData (activityId, name, value) values (?,?,?)");
$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.
@ -51,13 +51,18 @@ A reference to the current session.
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
sub create {
my $class = shift;
my $session = 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);
$self->set($properties);
return $self;
@ -102,7 +107,8 @@ Returns the value for a given property. See the set() method for details.
sub get {
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.
=head4 method
=head4 methodName
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.
=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
sub set {
@ -230,6 +240,7 @@ sub set {
} elsif ($properties->{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}{hourOfDay} = $properties->{hourOfDay} || $self->{_data}{hourOfDay} || "*";
$self->{_data}{dayOfMonth} = $properties->{dayOfMonth} || $self->{_data}{dayOfMonth} || "*";
@ -237,9 +248,9 @@ sub set {
$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}{methodName} = (exists $properties->{methodName}) ? $properties->{methodName} : $self->{_data}{methodName};
$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);
$self->session->db->setRow("WorkflowSchedule","taskId",$self->{_data});
$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.
@ -51,13 +51,18 @@ A reference to the current session.
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
sub create {
my $class = shift;
my $session = 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);
$self->set($properties);
return $self;
@ -102,7 +107,8 @@ Returns the value for a given property. See the set() method for details.
sub get {
my $self = shift;
return $self->{_data}{shift};
my $name = shift;
return $self->{_data}{$name};
}
#-------------------------------------------------------------------