-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_job_sequence.php
46 lines (46 loc) · 1.47 KB
/
get_job_sequence.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
$user_save_dir="./user_data";
$job_add_dir="./jobs";
function get_job_sequence(){
global $user_save_dir, $job_add_dir;
list($check, $msg) = postVal();
if($check){
$user_id = $_POST["user_id"];
$job_quene = scandir($job_add_dir);
$job_quene = array_diff($job_quene, array('..', '.', 'running.json'));
sort($job_quene);
if(in_array($user_id, $job_quene)){
$sequence = array_keys($job_quene, $user_id)[0];
}else{
$msg = "Not in the waiting execution queue!!";
}
$state_log_path = $user_save_dir."/".$_POST["user_id"]."/state.json";
if(is_file($state_log_path)){
$is_run = true;
}else{
$is_run = false;
}
}
if(!isset($msg)){
echo json_encode(array('is_run'=>$is_run, 'sequence'=>$sequence));
}elseif($msg === "Not in the waiting execution queue!!"){
echo json_encode(array('is_run'=>true, 'sequence'=>0));
}else{
echo json_encode(array('er_msg'=>$msg));
}
}
function postVal(){
global $user_save_dir, $job_add_dir;
if(!isset($_POST["user_id"])){
return array(false, "Inactive action!!");
}
if(!is_dir($job_add_dir."/".$_POST["user_id"])){
return array(false, "Not in the waiting execution queue!!");
}
if(!is_dir($user_save_dir."/".$_POST["user_id"])){
return array(false, "Job doesn't exist!!");
}
return array(true, null);
}
get_job_sequence();
?>