--- nfo/perl/libs/OEF/YAA/Jobs.pm 2003/04/18 16:04:03 1.4 +++ nfo/perl/libs/OEF/YAA/Jobs.pm 2003/05/13 09:07:36 1.5 @@ -1,7 +1,11 @@ ## ------------------------------------------------------------------------- -## $Id: Jobs.pm,v 1.4 2003/04/18 16:04:03 joko Exp $ +## $Id: Jobs.pm,v 1.5 2003/05/13 09:07:36 joko Exp $ ## ------------------------------------------------------------------------- ## $Log: Jobs.pm,v $ +## Revision 1.5 2003/05/13 09:07:36 joko +## updated api method signatures +## tasks running asynchronously +## ## Revision 1.4 2003/04/18 16:04:03 joko ## new api method: getTaskGroups - returns job groups (just a hash) from some configuration slot ## @@ -27,9 +31,9 @@ use base qw( OEF::API::Abstract ); -#use Data::Dumper; +use Data::Dumper; #use Data::Mungle::Transform::Deep qw( merge_to expand ); -use shortcuts qw( run_cmd ); +use shortcuts qw( run_cmd now ); # get logger instance my $logger = Log::Dispatch::Config->instance; @@ -61,33 +65,34 @@ hidden => 0, code => \&getTaskList, signature => [ - 'struct string', # w/o session - 'struct string struct', # session initialized (a struct containing a key 'RPCSESSID' will get propagated!) + 'struct struct', # w/o session + 'struct struct struct', # session initialized (a struct containing a key 'RPCSESSID' will get propagated!) ], help => "", protected => 1, }, { name => "getTaskInfo", - version => "0.02", + version => "0.03", hidden => 0, code => \&getTaskInfo, - signature => [ 'struct string' ], + signature => [ 'struct string', 'struct string struct' ], help => "", protected => 1, }, { name => "runTask", - version => "0.02", + version => "0.03", hidden => 0, code => \&runTask, - signature => [ 'string string' ], + #signature => [ 'string string', 'string string struct' ], + signature => [ 'struct string', 'struct string struct' ], help => "", protected => 1, }, { name => "getTaskGroups", - version => "0.02", + version => "0.03", hidden => 0, code => \&getTaskGroups, signature => [ 'struct', 'struct struct' ], @@ -105,40 +110,64 @@ sub getTaskList { my $srv = shift; - my $crit_key = shift; - $crit_key ||= ''; - - $logger->info( __PACKAGE__ . "->getTaskList( crit_key $crit_key )" ); + my $options = shift; + + #print Dumper($options); + + # XPath query expression (to be calculated here) + my $xpq = ''; #print Dumper($bizProcess); - my $file = $bizProcess->{app}->{storage}->{control}->{locator}->{files}->{jobs}; - - # build xpath query database - my $xpq_db = { - 'all-jobs-unfiltered' => '*/*', - }; - my $crit_db = { - 'all-jobs' => '/*', - 'to-backend' => '@source="backend" and (@action="import" or @action="load")', - 'to-frontend' => '@target="frontend"', - }; - $crit_db->{'about-import'} = "not ($crit_db->{'to-backend'} or $crit_db->{'to-frontend'})"; - - # select xpath query by criteria - my $xpq = ''; - if ($crit_key) { - if ($xpq_db->{$crit_key}) { - $xpq = $xpq_db->{$crit_key}; - } else { - my $crit = $crit_db->{$crit_key}; - if ($crit) { - $xpq = "*/target[*/*[$crit]]"; + + if ($options->{filter}) { + + my $crit_key = $options->{filter}; + $crit_key ||= ''; + + #$logger->info( __PACKAGE__ . "->getTaskList( crit_key|filter=$crit_key )" ); + + # build xpath query database + my $xpq_db = { + 'all-jobs-unfiltered' => '*/*', + }; + my $crit_db = { + 'all-jobs' => '/*', + 'to-backend' => '@source="backend" and (@action="import" or @action="load")', + 'to-frontend' => '@target="frontend"', + }; + $crit_db->{'about-import'} = "not ($crit_db->{'to-backend'} or $crit_db->{'to-frontend'})"; + + # select xpath query by criteria + #my $xpq = ''; + if ($crit_key) { + if ($xpq_db->{$crit_key}) { + $xpq = $xpq_db->{$crit_key}; + } else { + my $crit = $crit_db->{$crit_key}; + if ($crit) { + $xpq = "*/target[*/*[$crit]]"; + } } - } + } + + } elsif (my $query = $options->{query}) { + #$logger->info( __PACKAGE__ . "->getTaskList( query=$query )" ); + $xpq = $query; + #$xpq = '*/target[@name="dummy" or @name="' . $query . '"]'; + $xpq = '*/target[@name="dummy" or contains(@name, "' . $query . '")]'; } + #$xpq = '*/target[@name="transfer process dev to frontend"]'; + #$xpq = '/*[@name="transfer process dev to frontend"]'; + #my $crit = '/*[@name="transfer process dev to frontend"]'; + #my $crit = '@name="transfer process dev to frontend"'; + #$xpq = "*/target[*/*[$crit]]"; + #$xpq = "*/target[*/*[\@source=\"expekt\"]]"; + #$xpq = "*/target[*/*[\@target=\"dev\" or \@name=\"dummy\"]]"; + # issue the query + $logger->info( __PACKAGE__ . "->getTaskList( xpq=$xpq )" ); my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file ); $mdbe->sendQuery($xpq); $mdbe->circumflex('result'); @@ -174,14 +203,13 @@ my $crit = shift; $crit ||= ''; - $logger->info( __PACKAGE__ . "->getTaskInfo( crit $crit )" ); + $logger->info( __PACKAGE__ . "->getTaskInfo( crit=$crit )" ); my $task = _getTaskByName($crit); - #print Dumper($tasks); - return $task; my $jobname = $task->{name}; - + +=pod my $status = { metadata => { description => $task->{description}, @@ -191,8 +219,15 @@ locked => $self->{_pcontrol}->{$jobname}->{locked}, }, }; +=cut + + # enrich pure task metadata with job status information + $task->{status} = { + running => $self->{_pcontrol}->{$jobname}->{running}, + locked => $self->{_pcontrol}->{$jobname}->{locked}, + }; - return $status; + return $task; } @@ -208,17 +243,22 @@ #print "getTask - 1.1", "\n"; #print Dumper($task); + #print Dumper($self); # build command - my $jobname = $task->{name}; - my $command = "rap.pl $jobname"; - - # run - # FIXME: what about asynchronous job execution? - $self->{_pcontrol}->{$jobname}->{locked} = 1; - $self->{_pcontrol}->{$jobname}->{running} = 1; + my $rap = "rap.pl"; + #my $rap = 'C:\home\amo\develop\netfrag.org\nfo\perl\scripts\shortcuts\rap.pl'; + my $jobname = $task->{name}; + my $command = "$rap $jobname"; - run_cmd($command); + # run command + # FIXME: what about asynchronous job execution? + $self->{_pcontrol}->{$jobname}->{locked} = 1; + $self->{_pcontrol}->{$jobname}->{running} = 1; + + # new of 2003-05-11: USE_PATH and async + #run_cmd($command, "Executed from " . __PACKAGE__ . " at " . now(), { USE_PATH => 1 }); + run_cmd($command, "Executed from " . __PACKAGE__ . " at " . now(), { USE_PATH => 1, async => 1 }); =pod #system($command); @@ -233,10 +273,18 @@ print "result: $result", "\n"; =cut - $self->{_pcontrol}->{$jobname}->{locked} = 0; - $self->{_pcontrol}->{$jobname}->{running} = 0; + # FIXME: How to determine when execution has finished? + # Implement some dot.pid-mechanism? + # Possible solution: + # a) Spawn a helper process monitoring the long-running one. + # This one notifies the system when execution has finished and terminates itself afterwards. + # b) Have a dedicated process monitoring service running which gets notified of process startup and shutdown. + #$self->{_pcontrol}->{$jobname}->{locked} = 0; + #$self->{_pcontrol}->{$jobname}->{running} = 0; return 1; + #return $task; + }