@@ -4,142 +4,142 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Manager |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @var array |
|
| 9 | - */ |
|
| 10 | - protected $jobs = []; |
|
| 11 | - |
|
| 12 | - /** |
|
| 13 | - * For background jobs. |
|
| 14 | - * |
|
| 15 | - * @var array |
|
| 16 | - */ |
|
| 17 | - protected $processes = []; |
|
| 18 | - |
|
| 19 | - |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @param Job $job |
|
| 23 | - */ |
|
| 24 | - public function add(Job $job) |
|
| 25 | - { |
|
| 26 | - $this->jobs[] = $job; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param string $filename |
|
| 31 | - */ |
|
| 32 | - public function addCrontab($filename) |
|
| 33 | - { |
|
| 34 | - $crontab = new CrontabParser($filename); |
|
| 35 | - |
|
| 36 | - foreach ($crontab->getJobs() as $job) { |
|
| 37 | - $this->add($job); |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @param \DateTime|string $now |
|
| 45 | - * |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function getDueJobs($now = null) |
|
| 49 | - { |
|
| 50 | - $jobs = $this->jobs; |
|
| 51 | - |
|
| 52 | - $jobs = array_filter( |
|
| 53 | - $jobs, |
|
| 54 | - function ($job) use ($now) { |
|
| 55 | - return $job->isDue($now); |
|
| 56 | - } |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - return $jobs; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - public function getAllJobs() |
|
| 68 | - { |
|
| 69 | - return $this->jobs; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Run all due jobs in the foreground. |
|
| 76 | - * |
|
| 77 | - * @param \DateTime|string $now |
|
| 78 | - * |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function runInForeground($now = null) |
|
| 82 | - { |
|
| 83 | - $jobs = $this->getDueJobs($now); |
|
| 84 | - |
|
| 85 | - $outputs = []; |
|
| 86 | - |
|
| 87 | - foreach ($jobs as $job) { |
|
| 88 | - $outputs[] = $job->runInForeground(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - return $outputs; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Run all due jobs in the background. |
|
| 96 | - * |
|
| 97 | - * @param \DateTime|string $now |
|
| 98 | - * |
|
| 99 | - * @return array |
|
| 100 | - */ |
|
| 101 | - public function runInBackground($now = null) |
|
| 102 | - { |
|
| 103 | - $jobs = $this->getDueJobs($now); |
|
| 104 | - |
|
| 105 | - foreach ($jobs as $job) { |
|
| 106 | - $this->processes[] = $job->runInBackground(); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - return $this->processes; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Wait for all jobs running in the background to finish. |
|
| 116 | - */ |
|
| 117 | - public function wait() |
|
| 118 | - { |
|
| 119 | - foreach ($this->processes as $process) { |
|
| 120 | - $process->wait(); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Terminate all jobs running in the background. |
|
| 128 | - */ |
|
| 129 | - public function terminate() |
|
| 130 | - { |
|
| 131 | - foreach ($this->processes as $process) { |
|
| 132 | - $process->terminate(); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Kill all jobs running in the background. |
|
| 138 | - */ |
|
| 139 | - public function kill() |
|
| 140 | - { |
|
| 141 | - foreach ($this->processes as $process) { |
|
| 142 | - $process->kill(); |
|
| 143 | - } |
|
| 144 | - } |
|
| 7 | + /** |
|
| 8 | + * @var array |
|
| 9 | + */ |
|
| 10 | + protected $jobs = []; |
|
| 11 | + |
|
| 12 | + /** |
|
| 13 | + * For background jobs. |
|
| 14 | + * |
|
| 15 | + * @var array |
|
| 16 | + */ |
|
| 17 | + protected $processes = []; |
|
| 18 | + |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param Job $job |
|
| 23 | + */ |
|
| 24 | + public function add(Job $job) |
|
| 25 | + { |
|
| 26 | + $this->jobs[] = $job; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param string $filename |
|
| 31 | + */ |
|
| 32 | + public function addCrontab($filename) |
|
| 33 | + { |
|
| 34 | + $crontab = new CrontabParser($filename); |
|
| 35 | + |
|
| 36 | + foreach ($crontab->getJobs() as $job) { |
|
| 37 | + $this->add($job); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param \DateTime|string $now |
|
| 45 | + * |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + public function getDueJobs($now = null) |
|
| 49 | + { |
|
| 50 | + $jobs = $this->jobs; |
|
| 51 | + |
|
| 52 | + $jobs = array_filter( |
|
| 53 | + $jobs, |
|
| 54 | + function ($job) use ($now) { |
|
| 55 | + return $job->isDue($now); |
|
| 56 | + } |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + return $jobs; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + public function getAllJobs() |
|
| 68 | + { |
|
| 69 | + return $this->jobs; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Run all due jobs in the foreground. |
|
| 76 | + * |
|
| 77 | + * @param \DateTime|string $now |
|
| 78 | + * |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function runInForeground($now = null) |
|
| 82 | + { |
|
| 83 | + $jobs = $this->getDueJobs($now); |
|
| 84 | + |
|
| 85 | + $outputs = []; |
|
| 86 | + |
|
| 87 | + foreach ($jobs as $job) { |
|
| 88 | + $outputs[] = $job->runInForeground(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + return $outputs; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Run all due jobs in the background. |
|
| 96 | + * |
|
| 97 | + * @param \DateTime|string $now |
|
| 98 | + * |
|
| 99 | + * @return array |
|
| 100 | + */ |
|
| 101 | + public function runInBackground($now = null) |
|
| 102 | + { |
|
| 103 | + $jobs = $this->getDueJobs($now); |
|
| 104 | + |
|
| 105 | + foreach ($jobs as $job) { |
|
| 106 | + $this->processes[] = $job->runInBackground(); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + return $this->processes; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Wait for all jobs running in the background to finish. |
|
| 116 | + */ |
|
| 117 | + public function wait() |
|
| 118 | + { |
|
| 119 | + foreach ($this->processes as $process) { |
|
| 120 | + $process->wait(); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Terminate all jobs running in the background. |
|
| 128 | + */ |
|
| 129 | + public function terminate() |
|
| 130 | + { |
|
| 131 | + foreach ($this->processes as $process) { |
|
| 132 | + $process->terminate(); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Kill all jobs running in the background. |
|
| 138 | + */ |
|
| 139 | + public function kill() |
|
| 140 | + { |
|
| 141 | + foreach ($this->processes as $process) { |
|
| 142 | + $process->kill(); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | 145 | } |
@@ -9,79 +9,79 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class Process |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @var int |
|
| 14 | - */ |
|
| 15 | - protected $processID; |
|
| 12 | + /** |
|
| 13 | + * @var int |
|
| 14 | + */ |
|
| 15 | + protected $processID; |
|
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param int $processID |
|
| 21 | - */ |
|
| 22 | - public function __construct($processID) |
|
| 23 | - { |
|
| 24 | - $this->processID = $processID; |
|
| 19 | + /** |
|
| 20 | + * @param int $processID |
|
| 21 | + */ |
|
| 22 | + public function __construct($processID) |
|
| 23 | + { |
|
| 24 | + $this->processID = $processID; |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | - register_shutdown_function([$this, "wait"]); |
|
| 29 | - } |
|
| 28 | + register_shutdown_function([$this, "wait"]); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @return int |
|
| 35 | - */ |
|
| 36 | - public function getProcessID() |
|
| 37 | - { |
|
| 38 | - return $this->processID; |
|
| 39 | - } |
|
| 33 | + /** |
|
| 34 | + * @return int |
|
| 35 | + */ |
|
| 36 | + public function getProcessID() |
|
| 37 | + { |
|
| 38 | + return $this->processID; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Determine if this process is currently running. Defunct/zombie processes |
|
| 45 | - * are ignored. |
|
| 46 | - * |
|
| 47 | - * @return boolean |
|
| 48 | - */ |
|
| 49 | - public function isRunning() |
|
| 50 | - { |
|
| 51 | - $result = shell_exec(sprintf("ps %d", $this->getProcessID()) . " | grep -v '<defunct>'"); |
|
| 43 | + /** |
|
| 44 | + * Determine if this process is currently running. Defunct/zombie processes |
|
| 45 | + * are ignored. |
|
| 46 | + * |
|
| 47 | + * @return boolean |
|
| 48 | + */ |
|
| 49 | + public function isRunning() |
|
| 50 | + { |
|
| 51 | + $result = shell_exec(sprintf("ps %d", $this->getProcessID()) . " | grep -v '<defunct>'"); |
|
| 52 | 52 | |
| 53 | - return (count(preg_split("/\n/", $result)) > 2); |
|
| 54 | - } |
|
| 53 | + return (count(preg_split("/\n/", $result)) > 2); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Wait for the process to finish. |
|
| 60 | - */ |
|
| 61 | - public function wait() |
|
| 62 | - { |
|
| 63 | - pcntl_waitpid($this->getProcessID(), $status); |
|
| 64 | - } |
|
| 58 | + /** |
|
| 59 | + * Wait for the process to finish. |
|
| 60 | + */ |
|
| 61 | + public function wait() |
|
| 62 | + { |
|
| 63 | + pcntl_waitpid($this->getProcessID(), $status); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Terminate the process. |
|
| 70 | - * |
|
| 71 | - * @return boolean |
|
| 72 | - */ |
|
| 73 | - public function terminate() |
|
| 74 | - { |
|
| 75 | - return posix_kill($this->getProcessID(), SIGTERM); |
|
| 76 | - } |
|
| 68 | + /** |
|
| 69 | + * Terminate the process. |
|
| 70 | + * |
|
| 71 | + * @return boolean |
|
| 72 | + */ |
|
| 73 | + public function terminate() |
|
| 74 | + { |
|
| 75 | + return posix_kill($this->getProcessID(), SIGTERM); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Kill the process. |
|
| 80 | - * |
|
| 81 | - * @return boolean |
|
| 82 | - */ |
|
| 83 | - public function kill() |
|
| 84 | - { |
|
| 85 | - return posix_kill($this->getProcessID(), SIGKILL); |
|
| 86 | - } |
|
| 78 | + /** |
|
| 79 | + * Kill the process. |
|
| 80 | + * |
|
| 81 | + * @return boolean |
|
| 82 | + */ |
|
| 83 | + public function kill() |
|
| 84 | + { |
|
| 85 | + return posix_kill($this->getProcessID(), SIGKILL); |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -6,72 +6,72 @@ |
||
| 6 | 6 | |
| 7 | 7 | class System extends Job |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var string |
|
| 11 | - */ |
|
| 12 | - protected $command; |
|
| 9 | + /** |
|
| 10 | + * @var string |
|
| 11 | + */ |
|
| 12 | + protected $command; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $output; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $output; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param string $expression |
|
| 23 | - * @param string $command |
|
| 24 | - * @param string $output |
|
| 25 | - */ |
|
| 26 | - public function __construct($expression, $command, $output = null) |
|
| 27 | - { |
|
| 28 | - parent::__construct($expression); |
|
| 21 | + /** |
|
| 22 | + * @param string $expression |
|
| 23 | + * @param string $command |
|
| 24 | + * @param string $output |
|
| 25 | + */ |
|
| 26 | + public function __construct($expression, $command, $output = null) |
|
| 27 | + { |
|
| 28 | + parent::__construct($expression); |
|
| 29 | 29 | |
| 30 | - $this->command = $command; |
|
| 31 | - $this->output = $output; |
|
| 32 | - } |
|
| 30 | + $this->command = $command; |
|
| 31 | + $this->output = $output; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public function getCommand() |
|
| 40 | - { |
|
| 41 | - return $this->command; |
|
| 42 | - } |
|
| 36 | + /** |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public function getCommand() |
|
| 40 | + { |
|
| 41 | + return $this->command; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function getOutput() |
|
| 48 | - { |
|
| 49 | - return $this->output; |
|
| 50 | - } |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function getOutput() |
|
| 48 | + { |
|
| 49 | + return $this->output; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return string |
|
| 56 | - */ |
|
| 57 | - private function buildCommand() |
|
| 58 | - { |
|
| 59 | - $command = $this->getCommand(); |
|
| 54 | + /** |
|
| 55 | + * @return string |
|
| 56 | + */ |
|
| 57 | + private function buildCommand() |
|
| 58 | + { |
|
| 59 | + $command = $this->getCommand(); |
|
| 60 | 60 | |
| 61 | - if ($this->getOutput()) { |
|
| 62 | - $command .= ' > ' . $this->getOutput() . ' 2>&1'; |
|
| 63 | - } |
|
| 61 | + if ($this->getOutput()) { |
|
| 62 | + $command .= ' > ' . $this->getOutput() . ' 2>&1'; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - return $command; |
|
| 66 | - } |
|
| 65 | + return $command; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function runInForeground() |
|
| 74 | - { |
|
| 75 | - return shell_exec($this->buildCommand()); |
|
| 76 | - } |
|
| 70 | + /** |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function runInForeground() |
|
| 74 | + { |
|
| 75 | + return shell_exec($this->buildCommand()); |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -6,43 +6,43 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Callback extends Job |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var callable |
|
| 11 | - */ |
|
| 12 | - protected $callback; |
|
| 9 | + /** |
|
| 10 | + * @var callable |
|
| 11 | + */ |
|
| 12 | + protected $callback; |
|
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param string $expression |
|
| 18 | - * @param callable $callback |
|
| 19 | - */ |
|
| 20 | - public function __construct($expression, callable $callback) |
|
| 21 | - { |
|
| 22 | - parent::__construct($expression); |
|
| 16 | + /** |
|
| 17 | + * @param string $expression |
|
| 18 | + * @param callable $callback |
|
| 19 | + */ |
|
| 20 | + public function __construct($expression, callable $callback) |
|
| 21 | + { |
|
| 22 | + parent::__construct($expression); |
|
| 23 | 23 | |
| 24 | - $this->callback = $callback; |
|
| 25 | - } |
|
| 24 | + $this->callback = $callback; |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @return callable |
|
| 31 | - */ |
|
| 32 | - public function getCallback() |
|
| 33 | - { |
|
| 34 | - return $this->callback; |
|
| 35 | - } |
|
| 29 | + /** |
|
| 30 | + * @return callable |
|
| 31 | + */ |
|
| 32 | + public function getCallback() |
|
| 33 | + { |
|
| 34 | + return $this->callback; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return mixed |
|
| 41 | - */ |
|
| 42 | - public function runInForeground() |
|
| 43 | - { |
|
| 44 | - $contents = call_user_func($this->callback); |
|
| 39 | + /** |
|
| 40 | + * @return mixed |
|
| 41 | + */ |
|
| 42 | + public function runInForeground() |
|
| 43 | + { |
|
| 44 | + $contents = call_user_func($this->callback); |
|
| 45 | 45 | |
| 46 | - return $contents; |
|
| 47 | - } |
|
| 46 | + return $contents; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -7,62 +7,62 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Phalcon extends Job |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @var array|null |
|
| 12 | - */ |
|
| 13 | - protected $body; |
|
| 10 | + /** |
|
| 11 | + * @var array|null |
|
| 12 | + */ |
|
| 13 | + protected $body; |
|
| 14 | 14 | |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string $expression |
|
| 19 | - * @param array|null $body |
|
| 20 | - * |
|
| 21 | - * @throws Exception |
|
| 22 | - */ |
|
| 23 | - public function __construct($expression, $body = null) |
|
| 24 | - { |
|
| 25 | - $di = $this->getDI(); |
|
| 26 | - if (!($di instanceof DiInterface)) { |
|
| 27 | - throw new Exception("A dependency injection object is required to access internal services"); |
|
| 28 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $expression |
|
| 19 | + * @param array|null $body |
|
| 20 | + * |
|
| 21 | + * @throws Exception |
|
| 22 | + */ |
|
| 23 | + public function __construct($expression, $body = null) |
|
| 24 | + { |
|
| 25 | + $di = $this->getDI(); |
|
| 26 | + if (!($di instanceof DiInterface)) { |
|
| 27 | + throw new Exception("A dependency injection object is required to access internal services"); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - parent::__construct($expression); |
|
| 32 | + parent::__construct($expression); |
|
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | |
| 36 | - $this->body = $body; |
|
| 37 | - } |
|
| 36 | + $this->body = $body; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return array|null |
|
| 43 | - */ |
|
| 44 | - public function getBody() |
|
| 45 | - { |
|
| 46 | - return $this->body; |
|
| 47 | - } |
|
| 41 | + /** |
|
| 42 | + * @return array|null |
|
| 43 | + */ |
|
| 44 | + public function getBody() |
|
| 45 | + { |
|
| 46 | + return $this->body; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function runInForeground() |
|
| 55 | - { |
|
| 56 | - ob_start(); |
|
| 51 | + /** |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function runInForeground() |
|
| 55 | + { |
|
| 56 | + ob_start(); |
|
| 57 | 57 | |
| 58 | - $this->getDI()->get("console")->handle( |
|
| 59 | - $this->getBody() |
|
| 60 | - ); |
|
| 58 | + $this->getDI()->get("console")->handle( |
|
| 59 | + $this->getBody() |
|
| 60 | + ); |
|
| 61 | 61 | |
| 62 | - $contents = ob_get_contents(); |
|
| 62 | + $contents = ob_get_contents(); |
|
| 63 | 63 | |
| 64 | - ob_end_clean(); |
|
| 64 | + ob_end_clean(); |
|
| 65 | 65 | |
| 66 | - return $contents; |
|
| 67 | - } |
|
| 66 | + return $contents; |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -6,46 +6,46 @@ |
||
| 6 | 6 | |
| 7 | 7 | class CrontabParser |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var string |
|
| 11 | - */ |
|
| 12 | - protected $filename; |
|
| 9 | + /** |
|
| 10 | + * @var string |
|
| 11 | + */ |
|
| 12 | + protected $filename; |
|
| 13 | 13 | |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param string $filename |
|
| 18 | - * |
|
| 19 | - * @throws Exception |
|
| 20 | - */ |
|
| 21 | - public function __construct($filename) |
|
| 22 | - { |
|
| 23 | - if (!file_exists($filename)) { |
|
| 24 | - throw new Exception("Crontab file does not exist."); |
|
| 25 | - } |
|
| 16 | + /** |
|
| 17 | + * @param string $filename |
|
| 18 | + * |
|
| 19 | + * @throws Exception |
|
| 20 | + */ |
|
| 21 | + public function __construct($filename) |
|
| 22 | + { |
|
| 23 | + if (!file_exists($filename)) { |
|
| 24 | + throw new Exception("Crontab file does not exist."); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - $this->filename = $filename; |
|
| 28 | - } |
|
| 27 | + $this->filename = $filename; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 35 | - public function getJobs() |
|
| 36 | - { |
|
| 37 | - $contents = file_get_contents($this->filename); |
|
| 32 | + /** |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | + public function getJobs() |
|
| 36 | + { |
|
| 37 | + $contents = file_get_contents($this->filename); |
|
| 38 | 38 | |
| 39 | - $lines = explode(PHP_EOL, $contents); |
|
| 39 | + $lines = explode(PHP_EOL, $contents); |
|
| 40 | 40 | |
| 41 | - $jobs = []; |
|
| 41 | + $jobs = []; |
|
| 42 | 42 | |
| 43 | - foreach ($lines as $line) { |
|
| 44 | - if (preg_match("/^(\@\w+|[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+)\s+(.*)$/", $line, $matches)) { |
|
| 45 | - $jobs[] = new SystemJob($matches[1], $matches[2]); |
|
| 46 | - } |
|
| 47 | - } |
|
| 43 | + foreach ($lines as $line) { |
|
| 44 | + if (preg_match("/^(\@\w+|[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+)\s+(.*)$/", $line, $matches)) { |
|
| 45 | + $jobs[] = new SystemJob($matches[1], $matches[2]); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return $jobs; |
|
| 50 | - } |
|
| 49 | + return $jobs; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -7,74 +7,74 @@ |
||
| 7 | 7 | |
| 8 | 8 | abstract class Job extends Injectable |
| 9 | 9 | { |
| 10 | - /** |
|
| 11 | - * @var string |
|
| 12 | - */ |
|
| 13 | - protected $expression; |
|
| 10 | + /** |
|
| 11 | + * @var string |
|
| 12 | + */ |
|
| 13 | + protected $expression; |
|
| 14 | 14 | |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string $expression |
|
| 19 | - */ |
|
| 20 | - public function __construct($expression) |
|
| 21 | - { |
|
| 22 | - $this->expression = $expression; |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $expression |
|
| 19 | + */ |
|
| 20 | + public function __construct($expression) |
|
| 21 | + { |
|
| 22 | + $this->expression = $expression; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function getExpression() |
|
| 31 | - { |
|
| 32 | - return $this->expression; |
|
| 33 | - } |
|
| 27 | + /** |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function getExpression() |
|
| 31 | + { |
|
| 32 | + return $this->expression; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param \DateTime|string $datetime |
|
| 39 | - * |
|
| 40 | - * @return boolean |
|
| 41 | - */ |
|
| 42 | - public function isDue($datetime = "now") |
|
| 43 | - { |
|
| 44 | - return CronExpression::factory($this->getExpression())->isDue($datetime); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * @param \DateTime|string $datetime |
|
| 39 | + * |
|
| 40 | + * @return boolean |
|
| 41 | + */ |
|
| 42 | + public function isDue($datetime = "now") |
|
| 43 | + { |
|
| 44 | + return CronExpression::factory($this->getExpression())->isDue($datetime); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @return mixed |
|
| 51 | - */ |
|
| 52 | - abstract public function runInForeground(); |
|
| 49 | + /** |
|
| 50 | + * @return mixed |
|
| 51 | + */ |
|
| 52 | + abstract public function runInForeground(); |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @return Process |
|
| 56 | - * |
|
| 57 | - * @throws Exception |
|
| 58 | - */ |
|
| 59 | - public function runInBackground() |
|
| 60 | - { |
|
| 61 | - $processID = pcntl_fork(); |
|
| 54 | + /** |
|
| 55 | + * @return Process |
|
| 56 | + * |
|
| 57 | + * @throws Exception |
|
| 58 | + */ |
|
| 59 | + public function runInBackground() |
|
| 60 | + { |
|
| 61 | + $processID = pcntl_fork(); |
|
| 62 | 62 | |
| 63 | - if ($processID == -1) { |
|
| 64 | - throw new Exception("Failed to fork process."); |
|
| 65 | - } |
|
| 63 | + if ($processID == -1) { |
|
| 64 | + throw new Exception("Failed to fork process."); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - // This is the child process. |
|
| 68 | - if ($processID == 0) { |
|
| 69 | - // @codeCoverageIgnoreStart |
|
| 70 | - $this->runInForeground(); |
|
| 67 | + // This is the child process. |
|
| 68 | + if ($processID == 0) { |
|
| 69 | + // @codeCoverageIgnoreStart |
|
| 70 | + $this->runInForeground(); |
|
| 71 | 71 | |
| 72 | - exit(0); |
|
| 73 | - // @codeCoverageIgnoreEnd |
|
| 74 | - } |
|
| 72 | + exit(0); |
|
| 73 | + // @codeCoverageIgnoreEnd |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $process = new Process($processID); |
|
| 76 | + $process = new Process($processID); |
|
| 77 | 77 | |
| 78 | - return $process; |
|
| 79 | - } |
|
| 78 | + return $process; |
|
| 79 | + } |
|
| 80 | 80 | } |