diff --git a/docs/upgrades/upgrade_6.8.8-6.99.0.pl b/docs/upgrades/upgrade_6.8.8-6.99.0.pl index 4326042ad..fec662a98 100644 --- a/docs/upgrades/upgrade_6.8.8-6.99.0.pl +++ b/docs/upgrades/upgrade_6.8.8-6.99.0.pl @@ -276,7 +276,7 @@ sub updateCs { $session->db->write("alter table Collaboration add column getMailInterval int not null default 300"); $session->db->write("alter table Collaboration add column getMailCronId varchar(22) binary"); my $workflow = WebGUI::Workflow->create($session, { - isSerial=>1, + isSingleton=>1, type=>"WebGUI::Asset::Wobject::Collaboration", enabled=>1, description=>"Retrieves mail from a POP3 account for the given Collaboration System.", @@ -358,6 +358,7 @@ sub addWorkflow { description text, enabled int not null default 0, isSerial int not null default 0, + isSingleton int not null default 0, type varchar(255) not null default 'None' )"); $session->db->write("create table WorkflowActivity ( @@ -555,7 +556,7 @@ sub addWorkflow { title=>"Send Queued Email Messages", description => "Sends all the messages in the mail queue.", enabled=>1, - isSerial=>1, + isSingleton=>1, type=>"None" }, "pbworkflow000000000007"); $activity = $workflow->addActivity("WebGUI::Workflow::Activity::SendQueuedMailMessages", "pbwfactivity0000000021"); diff --git a/lib/WebGUI/Operation/WebGUI.pm b/lib/WebGUI/Operation/WebGUI.pm index 30dc04c25..6fd70a0d5 100644 --- a/lib/WebGUI/Operation/WebGUI.pm +++ b/lib/WebGUI/Operation/WebGUI.pm @@ -52,6 +52,7 @@ password and email address, as well as some other WebGUI settings. #------------------------------------------------------------------- sub www_setup { my $session = shift; + $session->http->setCacheControl("none"); $session->http->setMimeType("text/html"); return "" unless ($session->setting->get("specialState") eq "init"); my $i18n = WebGUI::International->new($session, "WebGUI"); diff --git a/lib/WebGUI/Operation/Workflow.pm b/lib/WebGUI/Operation/Workflow.pm index ffa62966a..82e1164cf 100644 --- a/lib/WebGUI/Operation/Workflow.pm +++ b/lib/WebGUI/Operation/Workflow.pm @@ -197,6 +197,13 @@ sub www_editWorkflow { label=>$i18n->get("is enabled"), hoverHelp=>$i18n->get("is enabled help") ); + $f->yesNo( + name=>"isSingleton", + value=>$workflow->get("isSingleton"), + defaultValue=>0, + label=>$i18n->get("is singleton"), + hoverHelp=>$i18n->get("is singleton help") + ); $f->yesNo( name=>"isSerial", value=>$workflow->get("isSerial"), diff --git a/lib/WebGUI/Workflow.pm b/lib/WebGUI/Workflow.pm index 1d7d5d0f0..4da576f26 100644 --- a/lib/WebGUI/Workflow.pm +++ b/lib/WebGUI/Workflow.pm @@ -393,9 +393,13 @@ A boolean indicating whether this workflow may be executed right now. A string indicating the type of object this workflow will be operating on. Valid values are "None", or any object type, like "WebGUI::VersionTag". +=head4 isSingleton + +A boolean indicating whether this workflow should be run as a singleton. If it's a singleton, then only one instance of the workflow will be allowed to be created at a given time. So if you try to create a new instance of it, and one instance is already created, the create() method will return undef instead of a reference to the object. + =head4 isSerial -A boolean indicating whether this workflow can be run in parallel or serial. If it's serial, then only one instance of the workflow will be allowed to be created at a given time. So if you try to create a new instance of it, and one instance is already created, the create() method will return undef instead of a reference to the object. +A boolean indicating whether this workflow should be run in serial mode. If it's run in serial, then only one instance of this workflow will be run at a given time, and all other instances of it will queue up. =cut @@ -412,6 +416,11 @@ sub set { } elsif ($properties->{isSerial} == 0) { $self->{_data}{isSerial} = 0; } + if ($properties->{isSingleton} == 1) { + $self->{_data}{isSingleton} = 1; + } elsif ($properties->{isSingleton} == 0) { + $self->{_data}{isSingleton} = 0; + } $self->{_data}{title} = $properties->{title} || $self->{_data}{title} || "Untitled"; $self->{_data}{description} = (exists $properties->{description}) ? $properties->{description} : $self->{_data}{description}; $self->{_data}{type} = $properties->{type} || $self->{_data}{type} || "None"; diff --git a/lib/WebGUI/Workflow/Instance.pm b/lib/WebGUI/Workflow/Instance.pm index 14980ad8f..57a2aa37d 100644 --- a/lib/WebGUI/Workflow/Instance.pm +++ b/lib/WebGUI/Workflow/Instance.pm @@ -63,10 +63,10 @@ sub create { my $session = shift; my $properties = shift; my $id = shift; - my ($isSerial) = $session->db->quickArray("select isSerial from Workflow where workflowId=?",[$properties->{workflowId}]); + my ($isSingleton) = $session->db->quickArray("select isSingleton from Workflow where workflowId=?",[$properties->{workflowId}]); my $params = (exists $properties->{parameters}) ? JSON::objToJson({parameters => $properties->{parameters}}) : undef; my ($count) = $session->db->quickArray("select count(*) from WorkflowInstance where workflowId=? and parameters=?",[$properties->{workflowId},$params]); - return undef if ($isSerial && $count); + return undef if ($isSingleton && $count); my $instanceId = $session->db->setRow("WorkflowInstance","instanceId",{instanceId=>"new", runningSince=>time()}, $id); my $self = $class->new($session, $instanceId); $properties->{notifySpectre} = 1 unless ($properties->{notifySpectre} eq "0"); @@ -244,6 +244,10 @@ sub run { my $workflow = $self->getWorkflow; return "undefined" unless (defined $workflow); return "disabled" unless ($workflow->get("enabled")); + if ($workflow->get("isSerial")) { + 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 + } my $activity = $workflow->getNextActivity($self->get("currentActivityId")); unless (defined $activity) { $self->delete; diff --git a/lib/WebGUI/i18n/English/Workflow.pm b/lib/WebGUI/i18n/English/Workflow.pm index 2df55eda8..49f32ea25 100644 --- a/lib/WebGUI/i18n/English/Workflow.pm +++ b/lib/WebGUI/i18n/English/Workflow.pm @@ -31,8 +31,20 @@ our $I18N = { lastUpdated => 0, }, - 'is serial help' => { + 'is singleton help' => { message => q|If yes is selected then only one instance of this workflow will be allowed to be created at one time. Generally speaking this would be a bad idea for approval workflows, but is probably a good idea for workflows that download emails from a remote server, to avoid getting duplicates.|, + context => q|the hover help for the is singleton field|, + lastUpdated => 0, + }, + + 'is singleton' => { + message => q|Is a singleton?|, + context => q|A question that asks the user whether this workflow may be instanciated multiple times concurrently or not.|, + lastUpdated => 0, + }, + + 'is serial help' => { + message => q|If yes is selected then only one instance of this workflow will be allowed to be run at one time, while new instances get queued up and wait for the running one to complete. This is generally bad for a workflow, but it can be good when multiple instances of workflow have to operate on the same data.|, context => q|the hover help for the is serial field|, lastUpdated => 0, },