/[cvs]/nfo/perl/libs/OEF/YAA/Jobs.pm
ViewVC logotype

Annotation of /nfo/perl/libs/OEF/YAA/Jobs.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Tue May 13 09:07:36 2003 UTC (21 years, 1 month ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +99 -52 lines
updated api method signatures
tasks running asynchronously

1 joko 1.1 ## -------------------------------------------------------------------------
2 joko 1.5 ## $Id: Jobs.pm,v 1.4 2003/04/18 16:04:03 joko Exp $
3 joko 1.1 ## -------------------------------------------------------------------------
4 joko 1.2 ## $Log: Jobs.pm,v $
5 joko 1.5 ## Revision 1.4 2003/04/18 16:04:03 joko
6     ## new api method: getTaskGroups - returns job groups (just a hash) from some configuration slot
7     ##
8 joko 1.4 ## Revision 1.3 2003/04/04 17:29:49 joko
9     ## updated signatures: session-based service
10     ## enabled method protection
11     ##
12 joko 1.3 ## Revision 1.2 2003/03/28 03:07:41 joko
13     ## minor fix: 'run_cmd' required here
14     ##
15 joko 1.2 ## Revision 1.1 2003/03/27 15:39:55 joko
16     ## initial commit, jobs -core and -api
17     ##
18 joko 1.1 ## -------------------------------------------------------------------------
19    
20    
21     package OEF::YAA::Jobs;
22    
23     use strict;
24     use warnings;
25    
26     use base qw( DesignPattern::Object );
27     use base qw( OEF::API::Abstract );
28    
29    
30 joko 1.5 use Data::Dumper;
31 joko 1.1 #use Data::Mungle::Transform::Deep qw( merge_to expand );
32 joko 1.5 use shortcuts qw( run_cmd now );
33 joko 1.1
34     # get logger instance
35     my $logger = Log::Dispatch::Config->instance;
36    
37    
38     #my $bizWorks = $main::bizWorks;
39     my $bizProcess = $main::bizProcess;
40     #my $process = $main::bizProcess;
41    
42     #print Dumper($bizProcess);
43     #push @{$process->{app}->{use_databases}}, 'control';
44     #my $boot = $main::boot;
45     #$boot->_bootDatabases();
46    
47     #our ($logger, $bizWorks, $bizProcess, $process, $boot);
48    
49     # ==============================
50     # api-method-declarations
51     # ==============================
52     # remote method declaration
53    
54     sub _api_init {
55     my $self = shift;
56     #return;
57     my $procs = [
58     {
59     name => "getTaskList",
60 joko 1.3 version => "0.03",
61 joko 1.1 hidden => 0,
62     code => \&getTaskList,
63 joko 1.3 signature => [
64 joko 1.5 'struct struct', # w/o session
65     'struct struct struct', # session initialized (a struct containing a key 'RPCSESSID' will get propagated!)
66 joko 1.3 ],
67 joko 1.1 help => "",
68 joko 1.3 protected => 1,
69 joko 1.1 },
70     {
71     name => "getTaskInfo",
72 joko 1.5 version => "0.03",
73 joko 1.1 hidden => 0,
74     code => \&getTaskInfo,
75 joko 1.5 signature => [ 'struct string', 'struct string struct' ],
76 joko 1.1 help => "",
77 joko 1.3 protected => 1,
78 joko 1.1 },
79     {
80     name => "runTask",
81 joko 1.5 version => "0.03",
82 joko 1.1 hidden => 0,
83     code => \&runTask,
84 joko 1.5 #signature => [ 'string string', 'string string struct' ],
85     signature => [ 'struct string', 'struct string struct' ],
86 joko 1.1 help => "",
87 joko 1.3 protected => 1,
88 joko 1.1 },
89 joko 1.4 {
90     name => "getTaskGroups",
91 joko 1.5 version => "0.03",
92 joko 1.4 hidden => 0,
93     code => \&getTaskGroups,
94     signature => [ 'struct', 'struct struct' ],
95     help => "",
96     protected => 0,
97     },
98 joko 1.1 ];
99     $self->register($procs);
100     }
101    
102    
103     # ==============================
104     # methods
105    
106    
107     sub getTaskList {
108     my $srv = shift;
109 joko 1.5 my $options = shift;
110    
111     #print Dumper($options);
112    
113     # XPath query expression (to be calculated here)
114     my $xpq = '';
115 joko 1.1
116     #print Dumper($bizProcess);
117     my $file = $bizProcess->{app}->{storage}->{control}->{locator}->{files}->{jobs};
118 joko 1.5
119     if ($options->{filter}) {
120    
121     my $crit_key = $options->{filter};
122     $crit_key ||= '';
123    
124     #$logger->info( __PACKAGE__ . "->getTaskList( crit_key|filter=$crit_key )" );
125    
126     # build xpath query database
127     my $xpq_db = {
128     'all-jobs-unfiltered' => '*/*',
129     };
130     my $crit_db = {
131     'all-jobs' => '/*',
132     'to-backend' => '@source="backend" and (@action="import" or @action="load")',
133     'to-frontend' => '@target="frontend"',
134     };
135     $crit_db->{'about-import'} = "not ($crit_db->{'to-backend'} or $crit_db->{'to-frontend'})";
136    
137     # select xpath query by criteria
138     #my $xpq = '';
139     if ($crit_key) {
140     if ($xpq_db->{$crit_key}) {
141     $xpq = $xpq_db->{$crit_key};
142     } else {
143     my $crit = $crit_db->{$crit_key};
144     if ($crit) {
145     $xpq = "*/target[*/*[$crit]]";
146     }
147 joko 1.1 }
148 joko 1.5 }
149    
150     } elsif (my $query = $options->{query}) {
151     #$logger->info( __PACKAGE__ . "->getTaskList( query=$query )" );
152     $xpq = $query;
153     #$xpq = '*/target[@name="dummy" or @name="' . $query . '"]';
154     $xpq = '*/target[@name="dummy" or contains(@name, "' . $query . '")]';
155 joko 1.1 }
156    
157 joko 1.5 #$xpq = '*/target[@name="transfer process dev to frontend"]';
158     #$xpq = '/*[@name="transfer process dev to frontend"]';
159     #my $crit = '/*[@name="transfer process dev to frontend"]';
160     #my $crit = '@name="transfer process dev to frontend"';
161     #$xpq = "*/target[*/*[$crit]]";
162     #$xpq = "*/target[*/*[\@source=\"expekt\"]]";
163     #$xpq = "*/target[*/*[\@target=\"dev\" or \@name=\"dummy\"]]";
164    
165 joko 1.1 # issue the query
166 joko 1.5 $logger->info( __PACKAGE__ . "->getTaskList( xpq=$xpq )" );
167 joko 1.1 my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file );
168     $mdbe->sendQuery($xpq);
169     $mdbe->circumflex('result');
170     my $tasks = $mdbe->toSimpleTree();
171    
172     #print Dumper($tasks);
173    
174     return $tasks;
175     }
176    
177    
178     sub _getTaskByName {
179     #my $self = shift;
180     my $name = shift;
181    
182     #print "getTaskByName!!!!!", "\n";
183    
184     $logger->info( __PACKAGE__ . "->getTaskByName( name $name )" );
185    
186     my $file = $bizProcess->{app}->{storage}->{control}->{locator}->{files}->{jobs};
187    
188     # issue the query
189     my $xpq = "*/target[\@name=\"$name\"]";
190     my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file );
191     $mdbe->sendQuery($xpq);
192     my $task = $mdbe->toSimpleTree();
193     return $task;
194    
195     }
196    
197     sub getTaskInfo {
198     my $self = shift;
199     my $crit = shift;
200     $crit ||= '';
201    
202 joko 1.5 $logger->info( __PACKAGE__ . "->getTaskInfo( crit=$crit )" );
203 joko 1.1
204     my $task = _getTaskByName($crit);
205    
206     my $jobname = $task->{name};
207 joko 1.5
208     =pod
209 joko 1.1 my $status = {
210     metadata => {
211     description => $task->{description},
212     },
213     jobstatus => {
214     running => $self->{_pcontrol}->{$jobname}->{running},
215     locked => $self->{_pcontrol}->{$jobname}->{locked},
216     },
217     };
218 joko 1.5 =cut
219    
220     # enrich pure task metadata with job status information
221     $task->{status} = {
222     running => $self->{_pcontrol}->{$jobname}->{running},
223     locked => $self->{_pcontrol}->{$jobname}->{locked},
224     };
225 joko 1.1
226 joko 1.5 return $task;
227 joko 1.1 }
228    
229    
230     sub runTask {
231     my $self = shift;
232     my $crit = shift;
233     $crit ||= '';
234    
235     $logger->info( __PACKAGE__ . "->runTask( crit $crit )" );
236    
237     #print "getTask - 1", "\n";
238     my $task = _getTaskByName($crit);
239     #print "getTask - 1.1", "\n";
240    
241     #print Dumper($task);
242 joko 1.5 #print Dumper($self);
243 joko 1.1
244     # build command
245 joko 1.5 my $rap = "rap.pl";
246     #my $rap = 'C:\home\amo\develop\netfrag.org\nfo\perl\scripts\shortcuts\rap.pl';
247     my $jobname = $task->{name};
248     my $command = "$rap $jobname";
249 joko 1.1
250 joko 1.5 # run command
251     # FIXME: what about asynchronous job execution?
252     $self->{_pcontrol}->{$jobname}->{locked} = 1;
253     $self->{_pcontrol}->{$jobname}->{running} = 1;
254    
255     # new of 2003-05-11: USE_PATH and async
256     #run_cmd($command, "Executed from " . __PACKAGE__ . " at " . now(), { USE_PATH => 1 });
257     run_cmd($command, "Executed from " . __PACKAGE__ . " at " . now(), { USE_PATH => 1, async => 1 });
258 joko 1.1
259     =pod
260     #system($command);
261     my $base = $bizProcess->{app}->{config}->{paths}->{base};
262     $command = "$base/bin/$command";
263     print "command: $command", "\n";
264     my $in; my $out; my $err;
265     #run $command, "", \$out, \$err or print "Could not execute $command.", "\n";
266     #my $result = run $command, '>&' or print "Could not execute $command.", "\n";
267     my $result = run $command, '2>&1' or print "Could not execute $command.", "\n";
268     #print Dumper($in, $out, $err);
269     print "result: $result", "\n";
270     =cut
271    
272 joko 1.5 # FIXME: How to determine when execution has finished?
273     # Implement some dot.pid-mechanism?
274     # Possible solution:
275     # a) Spawn a helper process monitoring the long-running one.
276     # This one notifies the system when execution has finished and terminates itself afterwards.
277     # b) Have a dedicated process monitoring service running which gets notified of process startup and shutdown.
278     #$self->{_pcontrol}->{$jobname}->{locked} = 0;
279     #$self->{_pcontrol}->{$jobname}->{running} = 0;
280 joko 1.1
281     return 1;
282 joko 1.5 #return $task;
283    
284 joko 1.1 }
285    
286    
287 joko 1.4 sub getTaskGroups {
288     my $self = shift;
289    
290     $logger->info( __PACKAGE__ . "->getTaskGroups()" );
291    
292     # emulate a row based result
293     my $jobgroups = $bizProcess->{app}->{config}->{jobs}->{groups};
294    
295     return $jobgroups;
296    
297     }
298 joko 1.1
299    
300     1;
301     __END__

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed