[Catalyst-commits] r6853 - in trunk/Catalyst-Engine-JobQueue-POE/lib/Catalyst: Engine/JobQueue JobQueue

kixx at dev.catalyst.perl.org kixx at dev.catalyst.perl.org
Thu Sep 6 16:52:18 GMT 2007


Author: kixx
Date: 2007-09-06 16:52:18 +0100 (Thu, 06 Sep 2007)
New Revision: 6853

Modified:
   trunk/Catalyst-Engine-JobQueue-POE/lib/Catalyst/Engine/JobQueue/POE.pm
   trunk/Catalyst-Engine-JobQueue-POE/lib/Catalyst/JobQueue/Job.pm
Log:
Move environment preparation and job stopping code to the Job object
Docfixes: spelling, add docs for new accessors and methods


Modified: trunk/Catalyst-Engine-JobQueue-POE/lib/Catalyst/Engine/JobQueue/POE.pm
===================================================================
--- trunk/Catalyst-Engine-JobQueue-POE/lib/Catalyst/Engine/JobQueue/POE.pm	2007-09-06 15:38:18 UTC (rev 6852)
+++ trunk/Catalyst-Engine-JobQueue-POE/lib/Catalyst/Engine/JobQueue/POE.pm	2007-09-06 15:52:18 UTC (rev 6853)
@@ -24,17 +24,6 @@
 # Enable for helpful debugging information
 sub DEBUG { $ENV{CATALYST_POE_DEBUG} || 0 } 
 
-sub CGI_ENV_DEFAULTS {
-    {
-        REMOTE_ADDR     => '127.0.0.1',
-        REMOTE_HOST     => 'localhost',
-        REQUEST_METHOD  => 'GET',
-        SERVER_NAME     => '127.0.0.1',
-        SERVER_PORT     => 80,
-        SERVER_PROTOCOL => 'HTTP/1.0',
-    }
-}
-
 sub CONFIG_DEFAULTS {
     {
         render => { to => [qw/log/] },
@@ -334,8 +323,8 @@
     my $job = $self->{jobs}->{$ID};
     DEBUG && warn "[Job $ID] STATUS: " . $job->last_status . "\n";
 
-    # remove from scheduler cleanup job 
-    $job->scheduler->delete;
+    # stop and cleanup job 
+    $job->stop;
     delete $self->{jobs}->{$ID};
 
     DEBUG && warn "[Job $ID] job_done\n";
@@ -348,7 +337,7 @@
     
     DEBUG && print "Running request " . $job->request->[0] . " as " .  $job->user . "\n";
     DEBUG && print "Setting up CGI Env for request\n";
-    $job->env( _make_cgi_env($job->request, $self->{global_env}) );
+    $job->prepare_env( $self->{global_env} );
     $kernel->yield( 'process' , $ID );
 
 }
@@ -397,25 +386,6 @@
     $sender->send($email);
 }
 
-sub _make_cgi_env
-{
-    my ( $request, $global_env ) = @_;
-
-    my @req_copy = @{$request};
-    my $path = shift @req_copy;
-    my $query_string = join('&', @req_copy);
-
-    my %env = %{ CGI_ENV_DEFAULTS() };
-    $env{PATH_INFO}     = $path || '';
-    $env{QUERY_STRING}  = $query_string;
-
-    # merge with global env
-    @env{ keys %{ $global_env } } = values %{ $global_env };
-
-    return \%env;
-
-}
-
 sub _parse_schedule_file
 {
 	my ($type, $filename) = @_;
@@ -557,7 +527,7 @@
 
 =item render
 
-Describes how the JobQueue shoudl handle responses
+Describes how the JobQueue should handle responses
 
 =over
 

Modified: trunk/Catalyst-Engine-JobQueue-POE/lib/Catalyst/JobQueue/Job.pm
===================================================================
--- trunk/Catalyst-Engine-JobQueue-POE/lib/Catalyst/JobQueue/Job.pm	2007-09-06 15:38:18 UTC (rev 6852)
+++ trunk/Catalyst-Engine-JobQueue-POE/lib/Catalyst/JobQueue/Job.pm	2007-09-06 15:52:18 UTC (rev 6853)
@@ -22,6 +22,17 @@
 
 sub DEBUG { $ENV{CATALYST_DEBUG} || 0; }
 
+sub CGI_ENV_DEFAULTS {
+    {
+        REMOTE_ADDR     => '127.0.0.1',
+        REMOTE_HOST     => 'localhost',
+        REQUEST_METHOD  => 'GET',
+        SERVER_NAME     => '127.0.0.1',
+        SERVER_PORT     => 80,
+        SERVER_PROTOCOL => 'HTTP/1.0',
+    }
+}
+
 sub new {
     my ($self, @args) = @_;
 
@@ -63,9 +74,30 @@
     );
 }
 
+sub prepare_env
+{
+	my ($self, $global_env) = @_;
+
+    my $request = $self->request;
+
+    my @req_copy = @{$request};
+    my $path = shift @req_copy;
+    my $query_string = join('&', @req_copy);
+
+    my %env = %{ CGI_ENV_DEFAULTS() };
+    $env{PATH_INFO}     = $path || '';
+    $env{QUERY_STRING}  = $query_string;
+
+    # merge with global env
+    @env{ keys %{ $global_env } } = values %{ $global_env };
+
+    $self->env(\%env);
+	
+}
+
 sub cleanup
 {
-    my $self = shift;
+    my ($self) = @_;
 
     for my $field ( qw/env context/ ) {
         $self->$field( '' );
@@ -74,6 +106,13 @@
     $self->flags( {} );
 }
 
+sub stop
+{
+	my ($self) = @_;
+
+	$self->scheduler->delete;
+}
+
 sub _parse_cron_spec
 {
 	my ($self, $spec) = @_;
@@ -136,6 +175,22 @@
 Constructs a new job object. Constructor parameters depend on the job type.
 C<ID> and C<flags> are filled in automatically.
 
+=head2 prepare_env( \%global_env );
+
+Prepares an environment variable hash starting with a set of default values,
+set PATH_INFO and QUERY_STRING from the parsed schedule line and fill in values
+from a global enviroment passed in as an argument. The resulting hash is stored 
+in L</env>.
+
+=head2 start( $poe_session, $handler_event )
+
+Starts a L<POE::Component::Cron> scheduler based on the schedule specs, attaches it
+to the given session and sets the POE event that will handle the cron events.
+
+=head2 stop
+
+Stop the job scheduler
+
 =head2 cleanup
 
 Clear temporary data, preparing the job for a new run through the engine.
@@ -178,6 +233,19 @@
 
 A reference to the job's cron scheduler.
 
+=head2 iterator
+
+A L<DateTime::Event> iterator which provide the scheduler with events 
+on which the job will be run.
+
+=head2 type 
+
+The schedule type of the job: can be C<cron> or C<at>.
+
+=head2 spec
+
+The schedule specification determines when a job will be run.
+
 =head1 CONFIGURATION AND ENVIRONMENT
  
 Catalyst::JobQueue::Job requires no configuration files or environment variables.
@@ -237,3 +305,7 @@
 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGES.n 1;
+
+=head1 SEE ALSO
+
+L<POE::Component::Cron>, L<DateTime::Event::Cron>




More information about the Catalyst-commits mailing list