diff --git a/docs/upgrades/upgrade_7.10.1-7.10.2.pl b/docs/upgrades/upgrade_7.10.1-7.10.2.pl index 9f4bb75c6..e7044997d 100644 --- a/docs/upgrades/upgrade_7.10.1-7.10.2.pl +++ b/docs/upgrades/upgrade_7.10.1-7.10.2.pl @@ -31,21 +31,21 @@ my $quiet; # this line required my $session = start(); # this line required # upgrade functions go here -addBackgroundProcessTable($session); -installBackgroundProcessCleanup($session); +addForkTable($session); +installForkCleanup($session); finish($session); # this line required #---------------------------------------------------------------------------- # Creates a new table for tracking background processes -sub addBackgroundProcessTable { +sub addForkTable { my $session = shift; my $db = $session->db; - my $sth = $db->dbh->table_info('', '', 'BackgroundProcess', 'TABLE'); + my $sth = $db->dbh->table_info('', '', 'Fork', 'TABLE'); return if ($sth->fetch); - print "\tAdding BackgroundProcess table..." unless $quiet; + print "\tAdding Fork table..." unless $quiet; my $sql = q{ - CREATE TABLE BackgroundProcess ( + CREATE TABLE Fork ( id CHAR(22), groupId CHAR(22), status LONGTEXT, @@ -64,16 +64,16 @@ sub addBackgroundProcessTable { #---------------------------------------------------------------------------- # install a workflow to clean up old background processes -sub installBackgroundProcessCleanup { +sub installForkCleanup { my $session = shift; - print "\tInstalling Background Process Cleanup workflow..." unless $quiet; - my $class = 'WebGUI::Workflow::Activity::RemoveOldBackgroundProcesses'; + print "\tInstalling Fork Cleanup workflow..." unless $quiet; + my $class = 'WebGUI::Workflow::Activity::RemoveOldForks'; $session->config->addToArray('workflowActivities/None', $class); my $wf = WebGUI::Workflow->new($session, 'pbworkflow000000000001'); my $a = first { ref $_ eq $class } @{ $wf->getActivities }; unless ($a) { $a = $wf->addActivity($class); - $a->set(title => 'Remove Old Background Processes'); + $a->set(title => 'Remove Old Forks'); }; print "DONE!\n" unless $quiet; } diff --git a/lib/WebGUI/AssetExportHtml.pm b/lib/WebGUI/AssetExportHtml.pm index f5673f7db..3f1d951f7 100644 --- a/lib/WebGUI/AssetExportHtml.pm +++ b/lib/WebGUI/AssetExportHtml.pm @@ -658,14 +658,14 @@ sub exportGetUrlAsPath { #------------------------------------------------------------------- -=head2 exportInBackground +=head2 exportInFork -Intended to be called by WebGUI::BackgroundProcess. Runs exportAsHtml on the +Intended to be called by WebGUI::Fork. Runs exportAsHtml on the specified asset and keeps a json structure as the status. =cut -sub exportInBackground { +sub exportInFork { my ($process, $args) = @_; my $self = WebGUI::Asset->new($process->session, delete $args->{assetId}); $args->{indexFileName} = delete $args->{index}; @@ -685,12 +685,12 @@ sub exportInBackground { my %reports = ( 'bad user privileges' => sub { shift->{badUserPrivileges} = 1 }, 'not exportable' => sub { shift->{notExportable} = 1 }, - 'exporting page' => sub { shift->{current} = 1 }, - 'done' => sub { + 'done' => sub { shift->{done} = 1 }, + 'exporting page' => sub { my $hash = shift; + $hash->{current} = 1; delete $last->{current}; $last = $hash; - $hash->{done} = 1; }, 'collateral notes' => sub { my ($hash, $text) = @_; @@ -705,6 +705,8 @@ sub exportInBackground { $process->update(sub { JSON::encode_json($tree) }); }; $self->exportAsHtml($args); + delete $last->{current}; + $process->update(JSON::encode_json($tree)); } #------------------------------------------------------------------- @@ -1027,8 +1029,8 @@ sub www_exportStatus { my @vars = qw( index depth userId extrasUploadsAction rootUrlAction exportUrl ); - my $process = WebGUI::BackgroundProcess->start( - $session, 'WebGUI::Asset', 'exportInBackground', { + my $process = WebGUI::Fork->start( + $session, 'WebGUI::Asset', 'exportInFork', { assetId => $self->getId, map { $_ => scalar $form->get($_) } @vars } diff --git a/lib/WebGUI/BackgroundProcess.pm b/lib/WebGUI/Fork.pm similarity index 85% rename from lib/WebGUI/BackgroundProcess.pm rename to lib/WebGUI/Fork.pm index 3a633240d..9776f89fd 100644 --- a/lib/WebGUI/BackgroundProcess.pm +++ b/lib/WebGUI/Fork.pm @@ -1,4 +1,4 @@ -package WebGUI::BackgroundProcess; +package WebGUI::Fork; use warnings; use strict; @@ -13,7 +13,7 @@ use Time::HiRes qw(sleep); =head1 NAME -WebGUI::BackgroundProcess +WebGUI::Fork =head1 DESCRIPTION @@ -36,16 +36,16 @@ status of. sub www_doWork { my $self = shift; my $session = $self->session; - my $process = WebGUI::BackgroundProcess->start( + my $process = WebGUI::Fork->start( $session, 'WebGUI::Some::Class', 'doWork', { some => 'data' } ); - # See WebGUI::Content::BackgroundProcess + # See WebGUI::Operation::Fork my $pairs = $process->contentPairs('DoWork'); $session->http->setRedirect($self->getUrl($pairs)); return 'redirect'; } - package WebGUI::Content::BackgroundProcess::DoWork; + package WebGUI::Operation::Fork::DoWork; sub handler { my $process = shift; @@ -77,8 +77,8 @@ status of. =head2 canView ($user?) Returns whether the current user (or the user passed in, if there is one) has -permission to view the status of the background process. By default, only -admins can view, but see setGroup. +permission to view the status of the fork. By default, only admins can view, +but see setGroup. =cut @@ -98,25 +98,24 @@ sub canView { =head2 contentPairs ($module, $pid) Returns a bit of query string useful for redirecting to a -WebGUI::Content::BackgroundProcess plugin. $module should be the bit that -comes after WebGUI::Content::BackgroundProcess, e.g. -$process->contentPairs('Foo') should return something like -"op=background;module=Foo;pid=adlfjafo87ad9f78a7", which will get dispatched -to WebGUI::Content::BackgroundProcess::Foo::handler($process) +WebGUI::Operation::Fork plugin. $module should be the bit that comes after +WebGUI::Operation::Fork, e.g. $process->contentPairs('Foo') should return +something like "op=fork;module=Foo;pid=adlfjafo87ad9f78a7", which will +get dispatched to WebGUI::Operation::Fork::Foo::handler($process) =cut sub contentPairs { my ( $self, $module ) = @_; my $pid = $self->getId; - return "op=background;module=$module;pid=$pid"; + return "op=fork;module=$module;pid=$pid"; } #----------------------------------------------------------------- =head2 create ( ) -Internal class method. Creates a new BackgroundProcess object and inserts a +Internal class method. Creates a new Fork object and inserts a blank row of data into the db. =cut @@ -266,7 +265,7 @@ sub forkAndExec { JSON::encode_json($request), sub { exec { $Config{perlpath} } - ( "webgui-background-$id", ( map {"-I$_"} @INC ), "-M$class", "-e$class->runCmd();", ) + ( "webgui-fork-$id", ( map {"-I$_"} @INC ), "-M$class", "-e$class->runCmd();", ) or die "Could not exec: $!"; } ); @@ -295,7 +294,7 @@ sub get { : '*'; my $id = $dbh->quote( $self->getId ); my @values = $db->quickArray("SELECT $key FROM $tbl WHERE id = $id"); - return wantarray ? @values : $values[0]; + return (@values > 1) ? @values : $values[0]; } #----------------------------------------------------------------- @@ -326,8 +325,7 @@ sub getGroupId { =head2 getId ( ) -The unique id for this background process. Note: this is NOT the pid, but a -WebGUI guid. +The unique id for this fork. Note: this is NOT the pid, but a WebGUI guid. =cut @@ -337,11 +335,11 @@ sub getId { shift->{id} } =head2 getStatus() -Signals the background process that it should report its next status, then -polls at $interval (can be fractional) seconds (default: .1) waiting for the -background process to claim that its status has been updated. Returns the -updated status. See setWait() for a way to change the interval (or disable -the waiting procedure entirely). +Signals the fork that it should report its next status, then polls at +$interval (can be fractional) seconds (default: .1) waiting for the fork to +claim that its status has been updated. Returns the updated status. See +setWait() for a way to change the interval (or disable the waiting procedure +entirely). =cut @@ -363,7 +361,7 @@ sub getStatus { =head2 init ( ) -Spawn a master process from which background processes will fork. The intent +Spawn a master process from which Forks will fork(). The intent is for this to be called once at server startup time, after you've preloaded modules and before you start listening for requests. Returns a filehandle that can be used to print requests to the master process, and which you almost @@ -385,7 +383,7 @@ sub init { return $pipe; } - $0 = 'webgui-background-master'; + $0 = 'webgui-fork-master'; $pipe->reader; local $/ = "\x{0}"; while ( my $request = $pipe->getline ) { @@ -399,7 +397,7 @@ sub init { =head2 isFinished ( ) -A simple flag indicating that background process is no longer running. +A simple flag indicating that the fork is no longer running. =cut @@ -409,8 +407,8 @@ sub isFinished { $_[0]->get('finished') } =head2 new ( $session, $id ) -Returns an object capable of checking on the status of the background process -indicated by $id. Returns undef if there is no such process. +Returns an object capable of checking on the status of the fork indicated by +$id. Returns undef if there is no such process. =cut @@ -558,8 +556,8 @@ sub sendRequestToMaster { Use this to control the pace at which getStatus will poll for updated statuses. By default, this is a tenth of a second. If you set it to 0, -getStatus will still signal the background process for an update, but will -take whatever is currently recorded as the status and return immediately. +getStatus will still signal the fork for an update, but will take whatever is +currently recorded as the status and return immediately. =cut @@ -569,13 +567,13 @@ sub setWait { $_[0]->{interval} = $_[1] } =head2 start ( $session, $module, $subname, $data ) -Class method. Executes $module::subname in a background thread with ($process, +Class method. Executes $module::subname in a forked process with ($process, $data) as its arguments. The only restriction on $data is that it be serializable by JSON. =head3 $0 -The process name (as it appears in ps) will be set to webgui-background-$id, +The process name (as it appears in ps) will be set to webgui-fork-$id, where $id is the value returned by $process->getId. It thus won't look like a modperl process to anyone monitoring the process table (wremonitor.pl, for example). @@ -609,18 +607,18 @@ data is stored in. =cut -sub tableName {'BackgroundProcess'} +sub tableName {'Fork'} #----------------------------------------------------------------- =head2 update ( $msg ) -Set a new status for the background process. This can be anything, and will -overwrite the old status. JSON is recommended for complex statuses. -Optionally, $msg can be a subroutine that returns the new status -- if your -status may take a long time to compute, you should use this, as you may be -able to avoid computing some (or all) of your status updates, depending on how -often they're being asked for. See the getStatus method for details. +Set a new status for the fork. This can be anything, and will overwrite the +old status. JSON is recommended for complex statuses. Optionally, $msg can +be a subroutine that returns the new status -- if your status may take a long +time to compute, you should use this, as you may be able to avoid computing +some (or all) of your status updates, depending on how often they're being +asked for. See the getStatus method for details. =cut diff --git a/lib/WebGUI/BackgroundProcess/AssetExport.pm b/lib/WebGUI/Fork/AssetExport.pm similarity index 97% rename from lib/WebGUI/BackgroundProcess/AssetExport.pm rename to lib/WebGUI/Fork/AssetExport.pm index e3b5f7ffe..e7440d888 100644 --- a/lib/WebGUI/BackgroundProcess/AssetExport.pm +++ b/lib/WebGUI/Fork/AssetExport.pm @@ -1,4 +1,4 @@ -package WebGUI::BackgroundProcess::AssetExport; +package WebGUI::Fork::AssetExport; =head1 LEGAL @@ -19,7 +19,7 @@ use warnings; =head1 NAME -WebGUI::BackgroundProcess::AssetExport +WebGUI::Fork::AssetExport =head1 DESCRIPTION @@ -149,7 +149,7 @@ STYLESHEET =head2 handler ( process ) -See WebGUI::Operation::BackgroundProcess. +See WebGUI::Operation::Fork. =cut diff --git a/lib/WebGUI/BackgroundProcess/Status.pm b/lib/WebGUI/Fork/Status.pm similarity index 96% rename from lib/WebGUI/BackgroundProcess/Status.pm rename to lib/WebGUI/Fork/Status.pm index fba674a9d..06c2ebd3b 100644 --- a/lib/WebGUI/BackgroundProcess/Status.pm +++ b/lib/WebGUI/Fork/Status.pm @@ -1,4 +1,4 @@ -package WebGUI::BackgroundProcess::Status; +package WebGUI::Fork::Status; use JSON; @@ -21,7 +21,7 @@ use warnings; =head1 NAME -WebGUI::BackgroundProcess::Status +WebGUI::Fork::Status =head1 DESCRIPTION diff --git a/lib/WebGUI/Operation.pm b/lib/WebGUI/Operation.pm index 444582270..7c9a9204b 100644 --- a/lib/WebGUI/Operation.pm +++ b/lib/WebGUI/Operation.pm @@ -76,7 +76,7 @@ Returns a hash reference containing operation and package names. sub getOperations { return { - 'background' => 'BackgroundProcess', + 'fork' => 'Fork', 'killSession' => 'ActiveSessions', 'viewActiveSessions' => 'ActiveSessions', diff --git a/lib/WebGUI/Operation/BackgroundProcess.pm b/lib/WebGUI/Operation/Fork.pm similarity index 72% rename from lib/WebGUI/Operation/BackgroundProcess.pm rename to lib/WebGUI/Operation/Fork.pm index ec2e2bf37..a0b2ccdfc 100644 --- a/lib/WebGUI/Operation/BackgroundProcess.pm +++ b/lib/WebGUI/Operation/Fork.pm @@ -1,4 +1,4 @@ -package WebGUI::Operation::BackgroundProcess; +package WebGUI::Operation::Fork; =head1 LEGAL @@ -17,16 +17,16 @@ package WebGUI::Operation::BackgroundProcess; use strict; use warnings; -use WebGUI::BackgroundProcess; +use WebGUI::Fork; use WebGUI::Pluggable; =head1 NAME -WebGUI::Operation::BackgroundProcess +WebGUI::Operation::Fork =head1 DESCRIPTION -URL dispatching for WebGUI::BackgroundProcess monitoring +URL dispatching for WebGUI::Fork monitoring =head1 SUBROUTINES @@ -39,18 +39,18 @@ These subroutines are available from this package: =head2 handler ( session ) Dispatches to the proper module based on the module form parameter if op is -background. Returns insufficient privilege page if the user doesn't pass -canView on the process before dispatching. +fork. Returns insufficient privilege page if the user doesn't pass canView on +the process before dispatching. =cut -sub www_background { +sub www_fork { my $session = shift; my $form = $session->form; my $module = $form->get('module') || 'Status'; my $pid = $form->get('pid') || return undef; - my $process = WebGUI::BackgroundProcess->new( $session, $pid ); + my $process = WebGUI::Fork->new( $session, $pid ); return $session->privilege->insufficient unless $process->canView; @@ -61,7 +61,7 @@ sub www_background { return undef; } - my $output = eval { WebGUI::Pluggable::run( "WebGUI::BackgroundProcess::$module", 'handler', [$process] ); }; + my $output = eval { WebGUI::Pluggable::run( "WebGUI::Fork::$module", 'handler', [$process] ); }; if ($@) { $log->error($@); @@ -69,6 +69,6 @@ sub www_background { } return $output; -} ## end sub www_background +} ## end sub www_fork 1; diff --git a/lib/WebGUI/Workflow/Activity/RemoveOldBackgroundProcesses.pm b/lib/WebGUI/Workflow/Activity/RemoveOldForks.pm similarity index 84% rename from lib/WebGUI/Workflow/Activity/RemoveOldBackgroundProcesses.pm rename to lib/WebGUI/Workflow/Activity/RemoveOldForks.pm index fd06e118a..209d29341 100644 --- a/lib/WebGUI/Workflow/Activity/RemoveOldBackgroundProcesses.pm +++ b/lib/WebGUI/Workflow/Activity/RemoveOldForks.pm @@ -1,4 +1,4 @@ -package WebGUI::Workflow::Activity::RemoveOldBackgroundProcesses; +package WebGUI::Workflow::Activity::RemoveOldForks; =head1 LEGAL @@ -20,15 +20,15 @@ use strict; use base 'WebGUI::Workflow::Activity'; use WebGUI::International; -use WebGUI::BackgroundProcess; +use WebGUI::Fork; =head1 NAME -WebGUI::Workflow::Activity::RemoveOldBackgroundProcesses +WebGUI::Workflow::Activity::RemoveOldForks =head1 DESCRIPTION -Remove background processes that are older than a configurable threshold. +Remove forks that are older than a configurable threshold. =head1 METHODS @@ -46,7 +46,7 @@ See WebGUI::Workflow::Activity::definition() for details. sub definition { my ( $class, $session, $definition ) = @_; - my $i18n = WebGUI::International->new( $session, 'Workflow_Activity_RemoveOldBackgroundProcesses' ); + my $i18n = WebGUI::International->new( $session, 'Workflow_Activity_RemoveOldForks' ); my %def = ( name => $i18n->get('activityName'), properties => { @@ -73,7 +73,7 @@ See WebGUI::Workflow::Activity::execute() for details. sub execute { my $self = shift; my $db = $self->session->db; - my $tbl = $db->dbh->quote_identifier( WebGUI::BackgroundProcess->tableName ); + my $tbl = $db->dbh->quote_identifier( WebGUI::Fork->tableName ); my $time = time - $self->get('interval'); $db->write( "DELETE FROM $tbl WHERE endTime <= ?", [$time] ); return $self->COMPLETE; diff --git a/lib/WebGUI/i18n/English/Workflow_Activity_RemoveOldBackgroundProcesses.pm b/lib/WebGUI/i18n/English/Workflow_Activity_RemoveOldForks.pm similarity index 70% rename from lib/WebGUI/i18n/English/Workflow_Activity_RemoveOldBackgroundProcesses.pm rename to lib/WebGUI/i18n/English/Workflow_Activity_RemoveOldForks.pm index 01ee9fc03..c93ebe4d2 100644 --- a/lib/WebGUI/i18n/English/Workflow_Activity_RemoveOldBackgroundProcesses.pm +++ b/lib/WebGUI/i18n/English/Workflow_Activity_RemoveOldForks.pm @@ -1,4 +1,4 @@ -package WebGUI::i18n::English::Workflow_Activity_RemoveOldBackgroundProcesses; +package WebGUI::i18n::English::Workflow_Activity_RemoveOldForks; use strict; @@ -12,7 +12,7 @@ our $I18N = { lastUpdated => 1285358250, }, 'activityName' => { - message => q|Remove Old Background Processes|, + message => q|Remove Old Forks|, lastUpdated => 1285358250, }, }; diff --git a/sbin/preload.perl b/sbin/preload.perl index abc4e8c54..0adbef505 100644 --- a/sbin/preload.perl +++ b/sbin/preload.perl @@ -41,9 +41,9 @@ WebGUI::Pluggable::findAndLoad( "WebGUI", WebGUI::Config->loadAllConfigs($webguiRoot); #---------------------------------------- -# WebGUI::BackgroundProcess initialization +# WebGUI::Fork initialization #---------------------------------------- -WebGUI::BackgroundProcess->init(); +WebGUI::Fork->init(); #---------------------------------------- # Logger diff --git a/t/BackgroundProcess.t b/t/Fork.t similarity index 94% rename from t/BackgroundProcess.t rename to t/Fork.t index 96d10929f..8e9d51909 100644 --- a/t/BackgroundProcess.t +++ b/t/Fork.t @@ -9,7 +9,7 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------ -# WebGUI::BackgroundProcess tests +# WebGUI::Fork tests use strict; use warnings; @@ -25,10 +25,10 @@ use JSON; use WebGUI::Test; use WebGUI::Session; -use WebGUI::BackgroundProcess; +use WebGUI::Fork; -my $class = 'WebGUI::BackgroundProcess'; -my $testClass = 'WebGUI::Test::BackgroundProcess'; +my $class = 'WebGUI::Fork'; +my $testClass = 'WebGUI::Test::Fork'; my $pipe = $class->init(); my $session = WebGUI::Test->session; diff --git a/t/lib/WebGUI/Test/BackgroundProcess.pm b/t/lib/WebGUI/Test/Fork.pm similarity index 87% rename from t/lib/WebGUI/Test/BackgroundProcess.pm rename to t/lib/WebGUI/Test/Fork.pm index 51912b2dc..ff86fbfed 100644 --- a/t/lib/WebGUI/Test/BackgroundProcess.pm +++ b/t/lib/WebGUI/Test/Fork.pm @@ -1,4 +1,4 @@ -package WebGUI::Test::BackgroundProcess; +package WebGUI::Test::Fork; sub simple { my ( $self, $arr ) = @_;