Commit 20243a74e792459707559ee699dc89766d9614c8

Authored by Benjamin Renard
2 parents 20fe3f49 ef39e50d
Exists in plot-request

Merge branch 'master' into plot-request

src/InputOutput/IHMImpl/Tools/IHMJobsManagerClass.php
... ... @@ -437,7 +437,9 @@ class IHMJobsManagerClass {
437 437 $res = $this->init();
438 438 if (!$res['success'])
439 439 return $res;
440   -
  440 +
  441 + $this->lockService();
  442 +
441 443 $job = $this->jobXml->getElementById($id);
442 444  
443 445 if (!isset($job)) {
... ... @@ -494,7 +496,9 @@ class IHMJobsManagerClass {
494 496 $job->setAttribute('info', $strInfo);
495 497  
496 498 $res = $this->jobXml->save($this->jobXmlName);
497   -
  499 +
  500 + $this->unlockService();
  501 +
498 502 if (!$res)
499 503 return array(
500 504 'success' => false,
... ... @@ -502,7 +506,9 @@ class IHMJobsManagerClass {
502 506  
503 507 return $this->getJobInfo($id);
504 508 }
505   -
  509 +
  510 + public function lockService(){}
  511 + public function unlockService(){}
506 512 /*
507 513 * @brief Get the list of jobs with a specific status
508 514 */
... ...
src/InputOutput/WSImpl/Config/WSConfigClass.php
... ... @@ -11,16 +11,17 @@ class WSConfigClass
11 11 const ORBIT = "getorbites";
12 12 const DATASET = "getdataset";
13 13  
14   - public static $timeToBatchMode = 300;
  14 + public static $timeToBatchMode = 240;
15 15 public static $enableBatch = true;
16 16 public static $file_prefix = "result_";
17   - public static $timeLimitQuery = 1800; // secs
  17 + public static $timeLimitQuery = 1800; // time limit for the current token in secs
18 18  
19 19 //TODO define during installation
20 20 private static $xslDir = "xml/";
21 21  
22 22 private static $wsResultDir = "WSRESULT";
23 23 private static $jobsFile = "WSjobs.xml";
  24 + private static $LockFile = "LOCK";
24 25  
25 26 private static $WebUrl;
26 27  
... ... @@ -44,6 +45,22 @@ class WSConfigClass
44 45 return IHMConfigClass::getDataDir().self::$wsResultDir.'/'.self::$jobsFile;
45 46 }
46 47  
  48 + public static function lockServices()
  49 + {
  50 + touch(IHMConfigClass::getDataDir().self::$wsResultDir.'/'.self::$LockFile);
  51 + }
  52 +
  53 + public static function isLockedServices()
  54 + {
  55 + return file_exists(IHMConfigClass::getDataDir().self::$wsResultDir.'/'.self::$LockFile);
  56 + }
  57 +
  58 + public static function unlockServices()
  59 + {
  60 + if (file_exists(IHMConfigClass::getDataDir().self::$wsResultDir.'/'.self::$LockFile))
  61 + unlink(IHMConfigClass::getDataDir().self::$wsResultDir.'/'.self::$LockFile);
  62 + }
  63 +
47 64 public static function getDataSetInfoDir()
48 65 {
49 66 return IHMConfigClass::getGenericDataPath().self::$dataSetInfoDir.'/';
... ...
src/InputOutput/WSImpl/Tools/WSJobsManagerClass.php
... ... @@ -41,6 +41,10 @@ class WSJobsManagerClass extends IHMJobsManagerClass {
41 41 return $res;
42 42 }
43 43 }
  44 +
  45 + while (WSConfigClass::isLockedServices())
  46 + sleep(1);
  47 +
44 48 $res = $this->jobXml->load($this->jobXmlName);
45 49 if (!$res) {
46 50 error_log("WebServices Error : Cannot load WSjobs.xml", 1, email);
... ... @@ -48,7 +52,7 @@ class WSJobsManagerClass extends IHMJobsManagerClass {
48 52 "success" => false,
49 53 "message" => "Cannot load jobs file");
50 54 }
51   -
  55 +
52 56 return array("success" => true);
53 57 }
54 58  
... ... @@ -105,7 +109,16 @@ class WSJobsManagerClass extends IHMJobsManagerClass {
105 109 'compression' => $compression
106 110 );
107 111 }
108   -
  112 +
  113 + public function lockService(){
  114 + if (!WSConfigClass::isLockedServices())
  115 + WSConfigClass::lockServices();
  116 + }
  117 +
  118 + public function unlockService(){
  119 + if (WSConfigClass::isLockedServices())
  120 + WSConfigClass::unlockServices();
  121 + }
109 122 /*
110 123 * @brief Add a new job
111 124 */
... ... @@ -113,10 +126,12 @@ class WSJobsManagerClass extends IHMJobsManagerClass {
113 126 $running, $start, $result, $exitcode)
114 127 {
115 128 $res = $this->init();
116   -
  129 +
117 130 if (!$res['success'])
118 131 return $res;
119   -
  132 +
  133 + $this->lockService();
  134 +
120 135 $key = WSInputOutputClass::getService();
121 136  
122 137 $newJob = $this->jobXml->createElement('job');
... ... @@ -124,39 +139,11 @@ class WSJobsManagerClass extends IHMJobsManagerClass {
124 139 $newJob->setAttribute('xml:id', $id);
125 140 $newJob->setAttribute('jobType', $key);
126 141  
127   -// switch ($key)
128   -// {
129   -// case 'parameter' :
130   -// $name = "download_".time();
131   -// $info = '';
132   -// foreach ($obj->list as $param)
133   -// {
134   -// $info .= ' '.$param->paramid; //data
135   -// }
136   -// break;
137   -// case 'plot' :
138   -// $name = "request_".time();
139   -// $info = '';
140   -// for ($i=0; $i < count($obj->children); $i++) {
141   -// for ($j=0; $j < count($obj->children[$i]->children); $j++) {
142   -// $info = $info.' '.$obj->children[$i]->children[$j]->paramid;
143   -// }
144   -// }
145   -// break;
146   -// default:
147   -// $name = "unknown_".time();
148   -// $info = '';
149   -// }
150   -
151   -// $newJob->setAttribute('name', $name);
152   -// $newJob->setAttribute('info', $info);
153 142 $newJob->setAttribute('result', $result);
154 143 $newJob->setAttribute('folder', $folder);
155 144 $newJob->setAttribute('start', date('d-m-Y H:i:s', $start));
156 145 $newJob->setAttribute('user', IHMConfigClass::getUserName());
157 146 $newJob->setAttribute('host', IHMConfigClass::getUserHost());
158   - //to know if know if it's an immediate job or not
159   -// $newJob->setAttribute('immediate', !$running);
160 147  
161 148 if ($running)
162 149 {
... ... @@ -182,49 +169,20 @@ class WSJobsManagerClass extends IHMJobsManagerClass {
182 169 }
183 170  
184 171 $rootJobNode->appendChild($newJob);
185   -
186   - if (!$this->jobXml->save($this->jobXmlName))
  172 +
  173 + if (!$this->jobXml->save($this->jobXmlName)) {
  174 + $this->unlockService();
187 175 return array("success" => false, "message" => "Cannot save job manager file");
188   -
  176 + }
  177 + $this->unlockService();
189 178 $this->saveRequestObjectFile($obj, $id);
  179 +
  180 + $res = $this->updateJobStatus($id, $running, $exitcode);
190 181  
191   - return $this->updateJobStatus($id, $running, $exitcode);
  182 + return $res;
  183 +
192 184 }
193 185  
194   - /*
195   - * @brief Update the status of a job
196   - */
197   -// public function updateJobStatus($id, $running, $exitcode)
198   -// {
199   -// $res = $this->init();
200   -// if (!$res['success'])
201   -// return $res;
202   -//
203   -// $job = $this->jobXml->getElementById($id);
204   -//
205   -// if (!isset($job))
206   -// return array("success" => false, "message" => "Cannot found job");
207   -//
208   -// $jobstatus = $this->getJobStatus($running,$exitcode);
209   -// $job->setAttribute('status', $jobstatus);
210   -//
211   -// if ($running)
212   -// $job->setAttribute('stop', 'unknown');
213   -// else if ($job->getAttribute('stop') == '' || $job->getAttribute('stop') == 'unknown')
214   -// {
215   -// $job->setAttribute('stop', date('d-m-Y H:i:s', time()));
216   -// $this->jobXml->getElementById($this->resRootNode[$job->getAttribute('jobType')])->appendChild($job);
217   -// }
218   -//
219   -// $res = $this->jobXml->save($this->jobXmlName);
220   -//
221   -// if (!$res)
222   -// return array(
223   -// 'success' => false,
224   -// 'message' => "Cannot save jobs status file");
225   -//
226   -// return $this->getJobInfo($id);
227   -// }
228 186  
229 187 /*
230 188 * @brief delete a job
... ...
src/Request/ProcessRequestImpl/Process/ProcessClass.php
... ... @@ -220,7 +220,7 @@ class ProcessClass
220 220 {
221 221 if (!call_user_func($callback,$this,$batchEnabled))
222 222 return false;
223   - sleep(2);
  223 + usleep(100000);
224 224 }
225 225 return true;
226 226 }
... ... @@ -246,7 +246,7 @@ class ProcessClass
246 246 $cmd = "pkill -TERM -P $this->pID";
247 247 //$cmd = 'kill '.$this->pID;
248 248 exec($cmd);
249   - return !$this->isRunning();
  249 + return TRUE;
250 250 }
251 251  
252 252 /*
... ...