added a screen for displaying the status of running workflows
This commit is contained in:
parent
f7c1c38ade
commit
f0bb16fb0b
5 changed files with 76 additions and 5 deletions
|
|
@ -351,7 +351,8 @@ sub addWorkflow {
|
||||||
methodName varchar(255),
|
methodName varchar(255),
|
||||||
parameters text,
|
parameters text,
|
||||||
runningSince bigint,
|
runningSince bigint,
|
||||||
lastUpdate bigint
|
lastUpdate bigint,
|
||||||
|
lastStatus varchar(15)
|
||||||
)");
|
)");
|
||||||
$session->db->write("create table WorkflowInstanceScratch (
|
$session->db->write("create table WorkflowInstanceScratch (
|
||||||
instanceId varchar(22) binary not null,
|
instanceId varchar(22) binary not null,
|
||||||
|
|
|
||||||
|
|
@ -282,6 +282,7 @@ sub getOperations {
|
||||||
'manageWorkflows' => 'WebGUI::Operation::Workflow',
|
'manageWorkflows' => 'WebGUI::Operation::Workflow',
|
||||||
'promoteWorkflowActivity' => 'WebGUI::Operation::Workflow',
|
'promoteWorkflowActivity' => 'WebGUI::Operation::Workflow',
|
||||||
'runWorkflow' => 'WebGUI::Operation::Workflow',
|
'runWorkflow' => 'WebGUI::Operation::Workflow',
|
||||||
|
'showRunningWorkflows' => 'WebGUI::Operation::Workflow',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -330,6 +330,7 @@ sub www_manageWorkflows {
|
||||||
$output .= '</table>';
|
$output .= '</table>';
|
||||||
my $ac = WebGUI::AdminConsole->new($session,"workflow");
|
my $ac = WebGUI::AdminConsole->new($session,"workflow");
|
||||||
$ac->addSubmenuItem($session->url->page("op=addWorkflow"), $i18n->get("add a new workflow"));
|
$ac->addSubmenuItem($session->url->page("op=addWorkflow"), $i18n->get("add a new workflow"));
|
||||||
|
$ac->addSubmenuItem($session->url->page("op=showRunningWorkflows"), $i18n->get("show running workflows"));
|
||||||
return $ac->render($output);
|
return $ac->render($output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -382,4 +383,45 @@ sub www_runWorkflow {
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_showRunningWorkflows ( )
|
||||||
|
|
||||||
|
Display a list of the running workflow instances.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_showRunningWorkflows {
|
||||||
|
my $session = shift;
|
||||||
|
return $session->privilege->insufficient() unless ($session->user->isInGroup("pbgroup000000000000015"));
|
||||||
|
my $i18n = WebGUI::International->new($session, "Workflow");
|
||||||
|
my $output = '<style>
|
||||||
|
.waiting { color: #808000; }
|
||||||
|
.complete { color: #008000; }
|
||||||
|
.error { color: #800000; }
|
||||||
|
.disabled { color: #808000; }
|
||||||
|
.done { color: #008000; }
|
||||||
|
.undefined { color: #800000; }
|
||||||
|
</style><table width="100%">';
|
||||||
|
my $rs = $session->db->read("select Workflow.title, WorkflowInstance.lastStatus, WorkflowInstance.runningSince, WorkflowInstance.lastUpdate from WorkflowInstance left join Workflow on WorkflowInstance.workflowId=Workflow.workflowId order by WorkflowInstance.runningSince desc");
|
||||||
|
while (my ($title, $status, $runningSince, $lastUpdate) = $rs->array) {
|
||||||
|
my $class = $status || "complete";
|
||||||
|
$output .= '<tr class="'.$class.'">'
|
||||||
|
.'<td>'.$title.'</td>'
|
||||||
|
.'<td>'.$session->datetime->epochToHuman($runningSince).'</td>';
|
||||||
|
if ($status) {
|
||||||
|
$output .= '<td>'
|
||||||
|
.$status.' / '.$session->datetime->epochToHuman($lastUpdate)
|
||||||
|
.'</td>';
|
||||||
|
}
|
||||||
|
$output .= "</tr>\n";
|
||||||
|
}
|
||||||
|
$output .= '</table>';
|
||||||
|
my $ac = WebGUI::AdminConsole->new($session,"workflow");
|
||||||
|
$ac->addSubmenuItem($session->url->page("op=addWorkflow"), $i18n->get("add a new workflow"));
|
||||||
|
$ac->addSubmenuItem($session->url->page("op=manageWorkflows"), $i18n->get("manage workflows"));
|
||||||
|
return $ac->render($output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -237,11 +237,20 @@ Executes the next iteration in this workflow. Returns a status code based upon w
|
||||||
sub run {
|
sub run {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $workflow = $self->getWorkflow;
|
my $workflow = $self->getWorkflow;
|
||||||
return "undefined" unless (defined $workflow);
|
unless (defined $workflow) {
|
||||||
return "disabled" unless ($workflow->get("enabled"));
|
$self->set({lastStatus=>"undefined", notifySpectre=>0});
|
||||||
|
return "undefined";
|
||||||
|
}
|
||||||
|
unless ($workflow->get("enabled")) {
|
||||||
|
$self->set({lastStatus=>"disabled", notifySpectre=>0});
|
||||||
|
return "disabled";
|
||||||
|
}
|
||||||
if ($workflow->get("isSerial")) {
|
if ($workflow->get("isSerial")) {
|
||||||
my ($firstId) = $self->session->db->quickArray("select workflowId from WorkflowInstance order by runningSince");
|
my ($firstId) = $self->session->db->quickArray("select workflowId from WorkflowInstance order by runningSince");
|
||||||
return "waiting" if ($workflow->getId ne $firstId); # must wait for currently running instance to complete
|
if ($workflow->getId ne $firstId) { # must wait for currently running instance to complete
|
||||||
|
$self->set({lastStatus=>"waiting", notifySpectre=>0});
|
||||||
|
return "waiting";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
my $activity = $workflow->getNextActivity($self->get("currentActivityId"));
|
my $activity = $workflow->getNextActivity($self->get("currentActivityId"));
|
||||||
unless (defined $activity) {
|
unless (defined $activity) {
|
||||||
|
|
@ -258,31 +267,38 @@ sub run {
|
||||||
eval($cmd);
|
eval($cmd);
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->session->errorHandler->error("Error loading activity class $class: ".$@);
|
$self->session->errorHandler->error("Error loading activity class $class: ".$@);
|
||||||
|
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
my $object = eval{ $class->$method($self->session, $params) };
|
my $object = eval{ $class->$method($self->session, $params) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->session->errorHandler->error("Error instanciating activity (".$activity->getId.") pass-in object: ".$@);
|
$self->session->errorHandler->error("Error instanciating activity (".$activity->getId.") pass-in object: ".$@);
|
||||||
|
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
unless (defined $object) {
|
unless (defined $object) {
|
||||||
$self->session->errorHandler->error("Pass in object came back undefined for activity (".$activity->getId.") using ".$class.", ".$method.", ".$params.".");
|
$self->session->errorHandler->error("Pass in object came back undefined for activity (".$activity->getId.") using ".$class.", ".$method.", ".$params.".");
|
||||||
|
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
$status = eval{$activity->execute($object, $self)};
|
$status = eval{$activity->execute($object, $self)};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->session->errorHandler->error("Caught exception executing workflow activity ".$activity->getId." for instance ".$self->getId." which reported ".$@);
|
$self->session->errorHandler->error("Caught exception executing workflow activity ".$activity->getId." for instance ".$self->getId." which reported ".$@);
|
||||||
|
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$status = $activity->execute(undef, $self);
|
$status = $activity->execute(undef, $self);
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->session->errorHandler->error("Caught exception executing workflow activity ".$activity->getId." for instance ".$self->getId." which reported ".$@);
|
$self->session->errorHandler->error("Caught exception executing workflow activity ".$activity->getId." for instance ".$self->getId." which reported ".$@);
|
||||||
|
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($status eq "complete") {
|
if ($status eq "complete") {
|
||||||
$self->set({"currentActivityId"=>$activity->getId, notifySpectre=>0});
|
$self->set({lastStatus=>"complete", "currentActivityId"=>$activity->getId, notifySpectre=>0});
|
||||||
|
} else {
|
||||||
|
$self->set({lastStatus=>"error", notifySpectre=>0});
|
||||||
}
|
}
|
||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
|
|
@ -335,12 +351,17 @@ The parameters to be passed into the constructor. Note that the system will alwa
|
||||||
|
|
||||||
The unique id of the activity in the workflow that needs to be executed next. If blank, it will execute the first activity in the workflow.
|
The unique id of the activity in the workflow that needs to be executed next. If blank, it will execute the first activity in the workflow.
|
||||||
|
|
||||||
|
=head4 lastStatus
|
||||||
|
|
||||||
|
See the run() method for a description of statuses.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub set {
|
sub set {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $properties = shift;
|
my $properties = shift;
|
||||||
$self->{_data}{priority} = $properties->{priority} || $self->{_data}{priority} || 2;
|
$self->{_data}{priority} = $properties->{priority} || $self->{_data}{priority} || 2;
|
||||||
|
$self->{_data}{lastStatus} = $properties->{lastStatus} || $self->{_data}{lastStatus};
|
||||||
$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}{methodName} = (exists $properties->{methodName}) ? $properties->{methodName} : $self->{_data}{methodName};
|
$self->{_data}{methodName} = (exists $properties->{methodName}) ? $properties->{methodName} : $self->{_data}{methodName};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
package WebGUI::i18n::English::Workflow;
|
package WebGUI::i18n::English::Workflow;
|
||||||
|
|
||||||
our $I18N = {
|
our $I18N = {
|
||||||
|
'show running workflows' => {
|
||||||
|
message => q|Show running workflows.|,
|
||||||
|
context => q|A label used to get to a display of running workflows.|,
|
||||||
|
lastUpdated => 0,
|
||||||
|
},
|
||||||
|
|
||||||
'no object' => {
|
'no object' => {
|
||||||
message => q|No Object|,
|
message => q|No Object|,
|
||||||
context => q|used when selecting an object type to be passed through a workflow|,
|
context => q|used when selecting an object type to be passed through a workflow|,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue