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