Completed
Push — master ( 3d1160...c03764 )
by Kevin
12:33
created
html/user/submit_rpc_handler.php 2 patches
Doc Comments   +28 added lines patch added patch discarded remove patch
@@ -30,6 +30,9 @@  discard block
 block discarded – undo
30 30
 ini_set('display_errors', true);
31 31
 ini_set('display_startup_errors', true);
32 32
 
33
+/**
34
+ * @param string $name
35
+ */
33 36
 function get_wu($name) {
34 37
     $name = BoincDb::escape_string($name);
35 38
     $wu = BoincWorkunit::lookup("name='$name'");
@@ -37,6 +40,9 @@  discard block
 block discarded – undo
37 40
     return $wu;
38 41
 }
39 42
 
43
+/**
44
+ * @param string $name
45
+ */
40 46
 function get_submit_app($name) {
41 47
     $name = BoincDb::escape_string($name);
42 48
     $app = BoincApp::lookup("name='$name'");
@@ -76,6 +82,9 @@  discard block
 block discarded – undo
76 82
     return $y;
77 83
 }
78 84
 
85
+/**
86
+ * @param SimpleXMLElement|null $template
87
+ */
79 88
 function est_elapsed_time($r, $template) {
80 89
     // crude estimate: batch FLOPs / project FLOPS
81 90
     //
@@ -131,6 +140,9 @@  discard block
 block discarded – undo
131 140
 // The arg is the batch-level template, if any.
132 141
 // Jobs may have their own templates.
133 142
 //
143
+/**
144
+ * @param SimpleXMLElement $template
145
+ */
134 146
 function validate_batch($jobs, $template) {
135 147
     $i = 0;
136 148
     $n = count($template->file_info);
@@ -200,6 +212,13 @@  discard block
 block discarded – undo
200 212
 
201 213
 // submit a list of jobs with a single create_work command.
202 214
 //
215
+/**
216
+ * @param stdClass $job_params
217
+ * @param double $priority
218
+ * @param integer $app_version_num
219
+ * @param string $input_template_filename
220
+ * @param string $output_template_filename
221
+ */
203 222
 function submit_jobs(
204 223
     $jobs, $job_params, $app, $batch_id, $priority, $app_version_num,
205 224
     $input_template_filename,        // batch-level; can also specify per job
@@ -294,6 +313,9 @@  discard block
 block discarded – undo
294 313
 // Check whether the template is already in our map.
295 314
 // If not, write it to a temp file.
296 315
 //
316
+/**
317
+ * @param stdClass $job
318
+ */
297 319
 function make_input_template($job) {
298 320
     global $input_templates;
299 321
     if (!array_key_exists($job->input_template_xml, $input_templates)) {
@@ -310,6 +332,9 @@  discard block
 block discarded – undo
310 332
 // A little different because these have to exist for life of job.
311 333
 // Store them in templates/tmp/, with content-based filenames
312 334
 //
335
+/**
336
+ * @param stdClass $job
337
+ */
313 338
 function make_output_template($job) {
314 339
     global $output_templates;
315 340
     if (!array_key_exists($job->output_template_xml, $output_templates)) {
@@ -508,6 +533,9 @@  discard block
 block discarded – undo
508 533
     ";
509 534
 }
510 535
 
536
+/**
537
+ * @param integer $get_cpu_time
538
+ */
511 539
 function print_batch_params($batch, $get_cpu_time) {
512 540
     $app = BoincApp::lookup_id($batch->app_id);
513 541
     if (!$app) $app->name = "none";
Please login to merge, or discard this patch.
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     if ($template) {
55 55
         $t = (double)$template->workunit->rsc_fpops_est;
56 56
     }
57
-    foreach($r->batch->job as $job) {
57
+    foreach ($r->batch->job as $job) {
58 58
         $y = (double)$job->rsc_fpops_est;
59 59
         if ($y) {
60 60
             $x += $y;
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 function est_elapsed_time($r, $template) {
80 80
     // crude estimate: batch FLOPs / project FLOPS
81 81
     //
82
-    return batch_flop_count($r, $template) / project_flops();
82
+    return batch_flop_count($r, $template)/project_flops();
83 83
 }
84 84
 
85 85
 // if batch-level input template filename was given, read it;
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 //
90 90
 function read_input_template($app, $r) {
91 91
     if ((isset($r->batch)) && (isset($r->batch->workunit_template_file)) && ($r->batch->workunit_template_file)) {
92
-        $path = project_dir() . "/templates/".$r->batch->workunit_template_file;
92
+        $path = project_dir()."/templates/".$r->batch->workunit_template_file;
93 93
     } else {
94
-        $path = project_dir() . "/templates/$app->name"."_in";
94
+        $path = project_dir()."/templates/$app->name"."_in";
95 95
     }
96 96
     if (file_exists($path)) {
97 97
         $x = simplexml_load_file($path);
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 function validate_batch($jobs, $template) {
135 135
     $i = 0;
136 136
     $n = count($template->file_info);
137
-    foreach($jobs as $job) {
137
+    foreach ($jobs as $job) {
138 138
         $m = count($job->input_files);
139 139
         if ($n != $m) {
140 140
             xml_error(-1, "wrong # of input files for job $i: need $n, got $m");
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 // stage all the files
190 190
 //
191 191
 function stage_files(&$jobs) {
192
-    foreach($jobs as $job) {
192
+    foreach ($jobs as $job) {
193 193
         foreach ($job->input_files as $file) {
194 194
             if ($file->mode != "remote") {
195 195
                 $file->name = stage_file($file);
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 //
203 203
 function submit_jobs(
204 204
     $jobs, $job_params, $app, $batch_id, $priority, $app_version_num,
205
-    $input_template_filename,        // batch-level; can also specify per job
205
+    $input_template_filename, // batch-level; can also specify per job
206 206
     $output_template_filename
207 207
 ) {
208 208
     global $input_templates, $output_templates;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     // one line per job
212 212
     //
213 213
     $x = "";
214
-    foreach($jobs as $job) {
214
+    foreach ($jobs as $job) {
215 215
         if ($job->name) {
216 216
             $x .= " --wu_name $job->name";
217 217
         }
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
         $x .= "\n";
244 244
     }
245 245
 
246
-    $errfile = "/tmp/create_work_" . getmypid() . ".err";
247
-    $cmd = "cd " . project_dir() . "; ./bin/create_work --appname $app->name --batch $batch_id --priority $priority";
246
+    $errfile = "/tmp/create_work_".getmypid().".err";
247
+    $cmd = "cd ".project_dir()."; ./bin/create_work --appname $app->name --batch $batch_id --priority $priority";
248 248
     if ($input_template_filename) {
249 249
         $cmd .= " --wu_template templates/$input_template_filename";
250 250
     }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
 //
341 341
 function xml_get_jobs($r) {
342 342
     $jobs = array();
343
-    foreach($r->batch->job as $j) {
343
+    foreach ($r->batch->job as $j) {
344 344
         $job = new StdClass;
345 345
         $job->input_files = array();
346 346
         $job->command_line = (string)$j->command_line;
@@ -420,14 +420,14 @@  discard block
 block discarded – undo
420 420
     // - use that for batch logical end time and job priority
421 421
     //
422 422
     $total_flops = 0;
423
-    foreach($jobs as $job) {
423
+    foreach ($jobs as $job) {
424 424
         //print_r($job);
425 425
         if ($job->rsc_fpops_est) {
426 426
             $total_flops += $job->rsc_fpops_est;
427 427
         } else if ($job->input_template && $job->input_template->workunit->rsc_fpops_est) {
428
-            $total_flops += (double) $job->input_template->workunit->rsc_fpops_est;
428
+            $total_flops += (double)$job->input_template->workunit->rsc_fpops_est;
429 429
         } else {
430
-            $x = (double) $template->workunit->rsc_fpops_est;
430
+            $x = (double)$template->workunit->rsc_fpops_est;
431 431
             if ($x) {
432 432
                 $total_flops += $x;
433 433
             } else {
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
             }
436 436
         }
437 437
     }
438
-    $cmd = "cd " . project_dir() . "/bin; ./adjust_user_priority --user $user->id --flops $total_flops --app $app->name";
438
+    $cmd = "cd ".project_dir()."/bin; ./adjust_user_priority --user $user->id --flops $total_flops --app $app->name";
439 439
     $x = exec($cmd);
440 440
     if (!is_numeric($x) || (double)$x == 0) {
441 441
         xml_error(-1, "$cmd returned $x");
@@ -459,15 +459,15 @@  discard block
 block discarded – undo
459 459
     }
460 460
     
461 461
     $job_params = new StdClass;
462
-    $job_params->rsc_disk_bound = (double) $r->job_params->rsc_disk_bound;
463
-    $job_params->rsc_fpops_est = (double) $r->job_params->rsc_fpops_est;
464
-    $job_params->rsc_fpops_bound = (double) $r->job_params->rsc_fpops_bound;
465
-    $job_params->rsc_memory_bound = (double) $r->job_params->rsc_memory_bound;
466
-    $job_params->delay_bound = (double) $r->job_params->delay_bound;
462
+    $job_params->rsc_disk_bound = (double)$r->job_params->rsc_disk_bound;
463
+    $job_params->rsc_fpops_est = (double)$r->job_params->rsc_fpops_est;
464
+    $job_params->rsc_fpops_bound = (double)$r->job_params->rsc_fpops_bound;
465
+    $job_params->rsc_memory_bound = (double)$r->job_params->rsc_memory_bound;
466
+    $job_params->delay_bound = (double)$r->job_params->delay_bound;
467 467
         // could add quorum-related stuff
468 468
 
469
-    $input_template_filename = (string) $r->batch->input_template_filename;
470
-    $output_template_filename = (string) $r->batch->output_template_filename;
469
+    $input_template_filename = (string)$r->batch->input_template_filename;
470
+    $output_template_filename = (string)$r->batch->output_template_filename;
471 471
         // possibly empty
472 472
     
473 473
     submit_jobs(
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 }
551 551
 
552 552
 function n_outfiles($wu) {
553
-    $path = project_dir() . "/$wu->output_template_filename";
553
+    $path = project_dir()."/$wu->output_template_filename";
554 554
     $r = simplexml_load_file($path);
555 555
     return count($r->file_info);
556 556
 }
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 ";
747 747
         if ($result->server_state == 5) {   // over?
748 748
             $paths = get_outfile_paths($result);
749
-            foreach($paths as $path) {
749
+            foreach ($paths as $path) {
750 750
                 if (is_file($path)) {
751 751
                     $size = filesize($path);
752 752
                     echo "        <outfile>
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
     } else {
787 787
         $results = BoincResult::enum("workunitid=$job_id");
788 788
         foreach ($results as $r) {
789
-            switch($r->outcome) {
789
+            switch ($r->outcome) {
790 790
             case 1:
791 791
             case 3:
792 792
             case 6:
@@ -894,8 +894,8 @@  discard block
 block discarded – undo
894 894
     }
895 895
 
896 896
     list($user, $user_submit) = authenticate_user($r, $app);
897
-    $in = file_get_contents(project_dir() . "/templates/".$app->name."_in");
898
-    $out = file_get_contents(project_dir() . "/templates/".$app->name."_out");
897
+    $in = file_get_contents(project_dir()."/templates/".$app->name."_in");
898
+    $out = file_get_contents(project_dir()."/templates/".$app->name."_out");
899 899
     if ($in === false || $out === false) {
900 900
         xml_error(-1, "template file missing");
901 901
     }
@@ -906,7 +906,7 @@  discard block
 block discarded – undo
906 906
 
907 907
 function ping($r) {
908 908
     xml_start_tag("ping");
909
-    BoincDb::get();     // errors out if DB down or web disabled
909
+    BoincDb::get(); // errors out if DB down or web disabled
910 910
     echo "<success>1</success>
911 911
         </ping>
912 912
     ";
@@ -972,10 +972,10 @@  discard block
 block discarded – undo
972 972
 if ($request_log) {
973 973
     $request_log_dir = parse_config(get_config(), "<log_dir>");
974 974
     if ($request_log_dir) {
975
-        $request_log = $request_log_dir . "/" . $request_log;
975
+        $request_log = $request_log_dir."/".$request_log;
976 976
     }
977 977
     if ($file = fopen($request_log, "a+")) {
978
-        fwrite($file, "\n<submit_rpc_handler date=\"" . date(DATE_ATOM) . "\">\n" . $_POST['request'] . "\n</submit_rpc_handler>\n");
978
+        fwrite($file, "\n<submit_rpc_handler date=\"".date(DATE_ATOM)."\">\n".$_POST['request']."\n</submit_rpc_handler>\n");
979 979
         fclose($file);
980 980
     }
981 981
 }
Please login to merge, or discard this patch.