/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to classes/scheduler.php

  • Committer: Suren A. Chilingaryan
  • Date: 2018-02-23 00:43:47 UTC
  • Revision ID: csa@suren.me-20180223004347-q0ull7zmz2ndajlt
Migrate some docker stuff to sources

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
    
31
31
    $this->lock = new LOCK("scheduler_$name");
32
32
    $this->sched_flags = $flags;
33
 
    $this->sched_path = "$dir/${ADEI_SETUP}_$name";
 
33
    $this->sched_path = "$dir/{$ADEI_SETUP}_$name";
34
34
 }
35
35
 
36
36
 function Schedule(REQUESTList $list) {
40
40
    foreach ($list as $sreq) {
41
41
        if (isset($user_req->props['db_server'])&&($user_req->props['db_server'] != $sreq->props['db_server'])) continue;
42
42
        if (isset($user_req->props['db_name'])&&($user_req->props['db_name'] != $sreq->props['db_name'])) continue;
43
 
        array_push($req_list, $sreq);
 
43
        array_push($req_list, $sreq->props);
44
44
    }
45
45
 
46
 
    $fname = "${this->sched_path}.cache";
 
46
    $fname = "{$this->sched_path}.cache";
47
47
    
48
48
    if (!$this->lock->Lock(LOCK::BLOCK|LOCK::EXCLUSIVE))
49
49
        throw new ADEIException(translate("Scheduler is not able to acquire a lock for \"%s\"", $fname));
56
56
 }
57
57
 
58
58
 function Get() {
59
 
    $iname = "${this->sched_path}.index";
60
 
    $fname = "${this->sched_path}.cache";
 
59
    $iname = "{$this->sched_path}.index";
 
60
    $fname = "{$this->sched_path}.cache";
61
61
    
62
62
    if (!$this->lock->Lock(LOCK::BLOCK|LOCK::EXCLUSIVE))
63
63
        throw new ADEIException(translate("Scheduler is not able to acquire a lock for \"%s\"", $fname));
64
64
 
65
65
    $data = file_get_contents($fname);
66
 
    if (($data === false)||(!is_array($data))) {
 
66
    if ($data === false) {
67
67
        $this->lock->Unlock();
68
68
        throw new ADEIException(translate("Scheduler is not able to read \"%s\"", $fname));
69
69
    }
70
70
    
71
 
    $req_list = unserialize($data);
72
 
    if ($req_list === false) {
 
71
    $props_list = unserialize($data);
 
72
    if (($props_list === false)||(!is_array($props_list))) {
73
73
        $this->lock->Unlock();
74
74
        throw new ADEIException(translate("Scheduler is not able to parse \"%s\"", $fname));
75
75
    }
76
76
    
77
77
    $index = file_get_contents($iname);
78
78
    if ($index === false) $index = 0;
79
 
    else if ($index >= count($req_list)) $index = 0;
 
79
    else if ($index >= count($props_list)) $index = 0;
80
80
    
81
81
    $bytes = file_put_contents($iname, ($index + 1));
82
82
    $this->lock->Unlock();
84
84
    if ($bytes === false)
85
85
        throw new ADEIException(translate("Scheduler is not able to open \"%s\"", $fname));
86
86
 
87
 
    return $req_list[$index];
88
 
 }
 
87
    return $props_list[$index];
 
88
 }
 
89
 
 
90
 function GetProps() {
 
91
    return $this->Get();
 
92
 }
 
93
 
89
94
}
90
95
?>
 
 
b'\\ No newline at end of file'