1
|
|
|
<?php namespace Comodojo\Extender\Socket; |
2
|
|
|
|
3
|
|
|
use \Comodojo\Extender\Schedule\Manager; |
4
|
|
|
use \Comodojo\Daemon\Process; |
5
|
|
|
use \Comodojo\Extender\Orm\Entities\Schedule; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @package Comodojo Extender |
9
|
|
|
* @author Marco Giovinazzi <[email protected]> |
10
|
|
|
* @license MIT |
11
|
|
|
* |
12
|
|
|
* LICENSE: |
13
|
|
|
* |
14
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
20
|
|
|
* THE SOFTWARE. |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
class ScheduleCommands { |
24
|
|
|
|
25
|
|
|
public function schedulerRefresh(Process $daemon, $data = null) { |
|
|
|
|
26
|
|
|
|
27
|
|
|
return $daemon->getWorkers()->get("scheduler")->getOutputChannel()->send('refresh'); |
|
|
|
|
28
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function schedulerAdd(Process $daemon, Schedule $schedule) { |
32
|
|
|
|
33
|
|
|
$id = self::getManager($daemon)->add($schedule); |
34
|
|
|
|
35
|
|
|
$this->schedulerRefresh($daemon); |
36
|
|
|
|
37
|
|
|
return $id; |
38
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function schedulerGet(Process $daemon, $id) { |
42
|
|
|
|
43
|
|
|
return self::getManager($daemon)->get($id); |
44
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function schedulerGetByName(Process $daemon, $name) { |
48
|
|
|
|
49
|
|
|
return self::getManager($daemon)->getByName($name); |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function schedulerEdit(Process $daemon, Schedule $schedule) { |
54
|
|
|
|
55
|
|
|
$edit = self::getManager($daemon)->edit($schedule); |
56
|
|
|
|
57
|
|
|
$this->schedulerRefresh($daemon); |
58
|
|
|
|
59
|
|
|
return $edit; |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function schedulerRemove(Process $daemon, $id) { |
64
|
|
|
|
65
|
|
|
$remove = self::getManager($daemon)->remove($id); |
66
|
|
|
|
67
|
|
|
$this->schedulerRefresh($daemon); |
68
|
|
|
|
69
|
|
|
return $remove; |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function schedulerRemoveByName(Process $daemon, $name) { |
74
|
|
|
|
75
|
|
|
$remove = self::getManager($daemon)->removeByName($name); |
76
|
|
|
|
77
|
|
|
$this->schedulerRefresh($daemon); |
78
|
|
|
|
79
|
|
|
return $remove; |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function schedulerEnable(Process $daemon, $id) { |
84
|
|
|
|
85
|
|
|
$enable = self::getManager($daemon)->enable($id); |
86
|
|
|
|
87
|
|
|
$this->schedulerRefresh($daemon); |
88
|
|
|
|
89
|
|
|
return $enable; |
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function schedulerEnableByName(Process $daemon, $name) { |
94
|
|
|
|
95
|
|
|
$enable = self::getManager($daemon)->enableByName($name); |
96
|
|
|
|
97
|
|
|
$this->schedulerRefresh($daemon); |
98
|
|
|
|
99
|
|
|
return $enable; |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function schedulerDisable(Process $daemon, $id) { |
104
|
|
|
|
105
|
|
|
$disable = self::getManager($daemon)->disable($id); |
106
|
|
|
|
107
|
|
|
$this->schedulerRefresh($daemon); |
108
|
|
|
|
109
|
|
|
return $disable; |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function schedulerDisableByName(Process $daemon, $name) { |
114
|
|
|
|
115
|
|
|
$disable = self::getManager($daemon)->disableByName($name); |
116
|
|
|
|
117
|
|
|
$this->schedulerRefresh($daemon); |
118
|
|
|
|
119
|
|
|
return $disable; |
120
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
View Code Duplication |
public function schedulerInfo(Process $daemon, $data = null) { |
|
|
|
|
124
|
|
|
|
125
|
|
|
$configuration = $daemon->getConfiguration(); |
|
|
|
|
126
|
|
|
$base_path = $configuration->get('base-path'); |
127
|
|
|
$lock_path = $configuration->get('run-path'); |
128
|
|
|
$lock_file = "$base_path/$lock_path/schedule.worker.lock"; |
129
|
|
|
|
130
|
|
|
return unserialize(file_get_contents($lock_file)); |
131
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
protected static function getManager(Process $daemon) { |
135
|
|
|
|
136
|
|
|
return new Manager( |
137
|
|
|
$daemon->getConfiguration(), |
|
|
|
|
138
|
|
|
$daemon->getLogger(), |
139
|
|
|
$daemon->getEvents() |
140
|
|
|
); |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.