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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Fri Apr 4 17:29:49 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.2: +12 -3 lines
updated signatures: session-based service
enabled method protection

1 ## -------------------------------------------------------------------------
2 ## $Id: Jobs.pm,v 1.2 2003/03/28 03:07:41 joko Exp $
3 ## -------------------------------------------------------------------------
4 ## $Log: Jobs.pm,v $
5 ## Revision 1.2 2003/03/28 03:07:41 joko
6 ## minor fix: 'run_cmd' required here
7 ##
8 ## Revision 1.1 2003/03/27 15:39:55 joko
9 ## initial commit, jobs -core and -api
10 ##
11 ## -------------------------------------------------------------------------
12
13
14 package OEF::YAA::Jobs;
15
16 use strict;
17 use warnings;
18
19 use base qw( DesignPattern::Object );
20 use base qw( OEF::API::Abstract );
21
22
23 #use Data::Dumper;
24 #use Data::Mungle::Transform::Deep qw( merge_to expand );
25 use shortcuts qw( run_cmd );
26
27 # get logger instance
28 my $logger = Log::Dispatch::Config->instance;
29
30
31 #my $bizWorks = $main::bizWorks;
32 my $bizProcess = $main::bizProcess;
33 #my $process = $main::bizProcess;
34
35 #print Dumper($bizProcess);
36 #push @{$process->{app}->{use_databases}}, 'control';
37 #my $boot = $main::boot;
38 #$boot->_bootDatabases();
39
40 #our ($logger, $bizWorks, $bizProcess, $process, $boot);
41
42 # ==============================
43 # api-method-declarations
44 # ==============================
45 # remote method declaration
46
47 sub _api_init {
48 my $self = shift;
49 #return;
50 my $procs = [
51 {
52 name => "getTaskList",
53 version => "0.03",
54 hidden => 0,
55 code => \&getTaskList,
56 signature => [
57 'struct string', # w/o session
58 'struct string struct', # session initialized (a struct containing a key 'RPCSESSID' will get propagated!)
59 ],
60 help => "",
61 protected => 1,
62 },
63 {
64 name => "getTaskInfo",
65 version => "0.02",
66 hidden => 0,
67 code => \&getTaskInfo,
68 signature => [ 'struct string' ],
69 help => "",
70 protected => 1,
71 },
72 {
73 name => "runTask",
74 version => "0.02",
75 hidden => 0,
76 code => \&runTask,
77 signature => [ 'string string' ],
78 help => "",
79 protected => 1,
80 },
81 ];
82 $self->register($procs);
83 }
84
85
86 # ==============================
87 # methods
88
89
90 sub getTaskList {
91 my $srv = shift;
92 my $crit_key = shift;
93 $crit_key ||= '';
94
95 $logger->info( __PACKAGE__ . "->getTaskList( crit_key $crit_key )" );
96
97 #print Dumper($bizProcess);
98
99 my $file = $bizProcess->{app}->{storage}->{control}->{locator}->{files}->{jobs};
100
101 # build xpath query database
102 my $xpq_db = {
103 'all-jobs-unfiltered' => '*/*',
104 };
105 my $crit_db = {
106 'all-jobs' => '/*',
107 'to-backend' => '@source="backend" and (@action="import" or @action="load")',
108 'to-frontend' => '@target="frontend"',
109 };
110 $crit_db->{'about-import'} = "not ($crit_db->{'to-backend'} or $crit_db->{'to-frontend'})";
111
112 # select xpath query by criteria
113 my $xpq = '';
114 if ($crit_key) {
115 if ($xpq_db->{$crit_key}) {
116 $xpq = $xpq_db->{$crit_key};
117 } else {
118 my $crit = $crit_db->{$crit_key};
119 if ($crit) {
120 $xpq = "*/target[*/*[$crit]]";
121 }
122 }
123 }
124
125 # issue the query
126 my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file );
127 $mdbe->sendQuery($xpq);
128 $mdbe->circumflex('result');
129 my $tasks = $mdbe->toSimpleTree();
130
131 #print Dumper($tasks);
132
133 return $tasks;
134 }
135
136
137 sub _getTaskByName {
138 #my $self = shift;
139 my $name = shift;
140
141 #print "getTaskByName!!!!!", "\n";
142
143 $logger->info( __PACKAGE__ . "->getTaskByName( name $name )" );
144
145 my $file = $bizProcess->{app}->{storage}->{control}->{locator}->{files}->{jobs};
146
147 # issue the query
148 my $xpq = "*/target[\@name=\"$name\"]";
149 my $mdbe = DesignPattern::Object->fromPackage('Data::Storage::Handler::XML', filename => $file );
150 $mdbe->sendQuery($xpq);
151 my $task = $mdbe->toSimpleTree();
152 return $task;
153
154 }
155
156 sub getTaskInfo {
157 my $self = shift;
158 my $crit = shift;
159 $crit ||= '';
160
161 $logger->info( __PACKAGE__ . "->getTaskInfo( crit $crit )" );
162
163 my $task = _getTaskByName($crit);
164 #print Dumper($tasks);
165 return $task;
166
167 my $jobname = $task->{name};
168
169 my $status = {
170 metadata => {
171 description => $task->{description},
172 },
173 jobstatus => {
174 running => $self->{_pcontrol}->{$jobname}->{running},
175 locked => $self->{_pcontrol}->{$jobname}->{locked},
176 },
177 };
178
179 return $status;
180 }
181
182
183 sub runTask {
184 my $self = shift;
185 my $crit = shift;
186 $crit ||= '';
187
188 $logger->info( __PACKAGE__ . "->runTask( crit $crit )" );
189
190 #print "getTask - 1", "\n";
191 my $task = _getTaskByName($crit);
192 #print "getTask - 1.1", "\n";
193
194 #print Dumper($task);
195
196 # build command
197 my $jobname = $task->{name};
198 my $command = "rap.pl $jobname";
199
200 # run
201 # FIXME: what about asynchronous job execution?
202 $self->{_pcontrol}->{$jobname}->{locked} = 1;
203 $self->{_pcontrol}->{$jobname}->{running} = 1;
204
205 run_cmd($command);
206
207 =pod
208 #system($command);
209 my $base = $bizProcess->{app}->{config}->{paths}->{base};
210 $command = "$base/bin/$command";
211 print "command: $command", "\n";
212 my $in; my $out; my $err;
213 #run $command, "", \$out, \$err or print "Could not execute $command.", "\n";
214 #my $result = run $command, '>&' or print "Could not execute $command.", "\n";
215 my $result = run $command, '2>&1' or print "Could not execute $command.", "\n";
216 #print Dumper($in, $out, $err);
217 print "result: $result", "\n";
218 =cut
219
220 $self->{_pcontrol}->{$jobname}->{locked} = 0;
221 $self->{_pcontrol}->{$jobname}->{running} = 0;
222
223 return 1;
224 }
225
226
227
228
229 1;
230 __END__

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