| @@ -4,74 +4,74 @@ | ||
| 4 | 4 | |
| 5 | 5 | abstract class Job extends \Phalcon\Di\Injectable | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * @var string | |
| 9 | - */ | |
| 10 | - protected $expression; | |
| 7 | + /** | |
| 8 | + * @var string | |
| 9 | + */ | |
| 10 | + protected $expression; | |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * @param string $expression | |
| 16 | - */ | |
| 17 | - public function __construct($expression) | |
| 18 | -    { | |
| 19 | - $this->expression = $expression; | |
| 20 | - } | |
| 14 | + /** | |
| 15 | + * @param string $expression | |
| 16 | + */ | |
| 17 | + public function __construct($expression) | |
| 18 | +	{ | |
| 19 | + $this->expression = $expression; | |
| 20 | + } | |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** | |
| 25 | - * @return string | |
| 26 | - */ | |
| 27 | - public function getExpression() | |
| 28 | -    { | |
| 29 | - return $this->expression; | |
| 30 | - } | |
| 24 | + /** | |
| 25 | + * @return string | |
| 26 | + */ | |
| 27 | + public function getExpression() | |
| 28 | +	{ | |
| 29 | + return $this->expression; | |
| 30 | + } | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** | |
| 35 | - * @param \DateTime|string $datetime | |
| 36 | - * | |
| 37 | - * @return boolean | |
| 38 | - */ | |
| 39 | - public function isDue($datetime = "now") | |
| 40 | -    { | |
| 41 | - return \Cron\CronExpression::factory($this->getExpression())->isDue($datetime); | |
| 42 | - } | |
| 34 | + /** | |
| 35 | + * @param \DateTime|string $datetime | |
| 36 | + * | |
| 37 | + * @return boolean | |
| 38 | + */ | |
| 39 | + public function isDue($datetime = "now") | |
| 40 | +	{ | |
| 41 | + return \Cron\CronExpression::factory($this->getExpression())->isDue($datetime); | |
| 42 | + } | |
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | |
| 46 | - /** | |
| 47 | - * @return mixed | |
| 48 | - */ | |
| 49 | - abstract public function runInForeground(); | |
| 46 | + /** | |
| 47 | + * @return mixed | |
| 48 | + */ | |
| 49 | + abstract public function runInForeground(); | |
| 50 | 50 | |
| 51 | - /** | |
| 52 | - * @return Process | |
| 53 | - * | |
| 54 | - * @throws Exception | |
| 55 | - */ | |
| 56 | - public function runInBackground() | |
| 57 | -    { | |
| 58 | - $processID = pcntl_fork(); | |
| 51 | + /** | |
| 52 | + * @return Process | |
| 53 | + * | |
| 54 | + * @throws Exception | |
| 55 | + */ | |
| 56 | + public function runInBackground() | |
| 57 | +	{ | |
| 58 | + $processID = pcntl_fork(); | |
| 59 | 59 | |
| 60 | -        if ($processID == -1) { | |
| 61 | -            throw new Exception("Failed to fork process."); | |
| 62 | - } | |
| 60 | +		if ($processID == -1) { | |
| 61 | +			throw new Exception("Failed to fork process."); | |
| 62 | + } | |
| 63 | 63 | |
| 64 | - // This is the child process. | |
| 65 | -        if ($processID == 0) { | |
| 66 | - // @codeCoverageIgnoreStart | |
| 67 | - $this->runInForeground(); | |
| 64 | + // This is the child process. | |
| 65 | +		if ($processID == 0) { | |
| 66 | + // @codeCoverageIgnoreStart | |
| 67 | + $this->runInForeground(); | |
| 68 | 68 | |
| 69 | - exit(0); | |
| 70 | - // @codeCoverageIgnoreEnd | |
| 71 | - } | |
| 69 | + exit(0); | |
| 70 | + // @codeCoverageIgnoreEnd | |
| 71 | + } | |
| 72 | 72 | |
| 73 | - $process = new Process($processID); | |
| 73 | + $process = new Process($processID); | |
| 74 | 74 | |
| 75 | - return $process; | |
| 76 | - } | |
| 75 | + return $process; | |
| 76 | + } | |
| 77 | 77 | } | 
| @@ -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 | } | 
| @@ -51,7 +51,7 @@ | ||
| 51 | 51 | |
| 52 | 52 | $jobs = array_filter( | 
| 53 | 53 | $jobs, | 
| 54 | -            function ($job) use ($now) { | |
| 54 | +            function($job) use ($now) { | |
| 55 | 55 | return $job->isDue($now); | 
| 56 | 56 | } | 
| 57 | 57 | ); | 
| @@ -4,46 +4,46 @@ | ||
| 4 | 4 | |
| 5 | 5 | class CrontabParser | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * @var string | |
| 9 | - */ | |
| 10 | - protected $filename; | |
| 7 | + /** | |
| 8 | + * @var string | |
| 9 | + */ | |
| 10 | + protected $filename; | |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * @param string $filename | |
| 16 | - * | |
| 17 | - * @throws Exception | |
| 18 | - */ | |
| 19 | - public function __construct($filename) | |
| 20 | -    { | |
| 21 | -        if (!file_exists($filename)) { | |
| 22 | -            throw new Exception("Crontab file does not exist."); | |
| 23 | - } | |
| 14 | + /** | |
| 15 | + * @param string $filename | |
| 16 | + * | |
| 17 | + * @throws Exception | |
| 18 | + */ | |
| 19 | + public function __construct($filename) | |
| 20 | +	{ | |
| 21 | +		if (!file_exists($filename)) { | |
| 22 | +			throw new Exception("Crontab file does not exist."); | |
| 23 | + } | |
| 24 | 24 | |
| 25 | - $this->filename = $filename; | |
| 26 | - } | |
| 25 | + $this->filename = $filename; | |
| 26 | + } | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** | |
| 31 | - * @return array | |
| 32 | - */ | |
| 33 | - public function getJobs() | |
| 34 | -    { | |
| 35 | - $contents = file_get_contents($this->filename); | |
| 30 | + /** | |
| 31 | + * @return array | |
| 32 | + */ | |
| 33 | + public function getJobs() | |
| 34 | +	{ | |
| 35 | + $contents = file_get_contents($this->filename); | |
| 36 | 36 | |
| 37 | - $lines = explode(PHP_EOL, $contents); | |
| 37 | + $lines = explode(PHP_EOL, $contents); | |
| 38 | 38 | |
| 39 | - $jobs = []; | |
| 39 | + $jobs = []; | |
| 40 | 40 | |
| 41 | -        foreach ($lines as $line) { | |
| 42 | -            if (preg_match("/^(\@\w+|[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+)\s+(.*)$/", $line, $matches)) { | |
| 43 | - $jobs[] = new Job\System($matches[1], $matches[2]); | |
| 44 | - } | |
| 45 | - } | |
| 41 | +		foreach ($lines as $line) { | |
| 42 | +			if (preg_match("/^(\@\w+|[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+\s[^\s]+)\s+(.*)$/", $line, $matches)) { | |
| 43 | + $jobs[] = new Job\System($matches[1], $matches[2]); | |
| 44 | + } | |
| 45 | + } | |
| 46 | 46 | |
| 47 | - return $jobs; | |
| 48 | - } | |
| 47 | + return $jobs; | |
| 48 | + } | |
| 49 | 49 | } | 
| @@ -4,62 +4,62 @@ | ||
| 4 | 4 | |
| 5 | 5 | class Phalcon extends \Sid\Phalcon\Cron\Job | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * @var array|null | |
| 9 | - */ | |
| 10 | - protected $body; | |
| 7 | + /** | |
| 8 | + * @var array|null | |
| 9 | + */ | |
| 10 | + protected $body; | |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * @param string $expression | |
| 16 | - * @param array|null $body | |
| 17 | - * | |
| 18 | - * @throws Exception | |
| 19 | - */ | |
| 20 | - public function __construct($expression, $body = null) | |
| 21 | -    { | |
| 22 | - $di = $this->getDI(); | |
| 23 | -        if (!($di instanceof \Phalcon\DiInterface)) { | |
| 24 | -            throw new Exception("A dependency injection object is required to access internal services"); | |
| 25 | - } | |
| 14 | + /** | |
| 15 | + * @param string $expression | |
| 16 | + * @param array|null $body | |
| 17 | + * | |
| 18 | + * @throws Exception | |
| 19 | + */ | |
| 20 | + public function __construct($expression, $body = null) | |
| 21 | +	{ | |
| 22 | + $di = $this->getDI(); | |
| 23 | +		if (!($di instanceof \Phalcon\DiInterface)) { | |
| 24 | +			throw new Exception("A dependency injection object is required to access internal services"); | |
| 25 | + } | |
| 26 | 26 | |
| 27 | 27 | |
| 28 | 28 | |
| 29 | - parent::__construct($expression); | |
| 29 | + parent::__construct($expression); | |
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | - $this->body = $body; | |
| 34 | - } | |
| 33 | + $this->body = $body; | |
| 34 | + } | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | 37 | |
| 38 | - /** | |
| 39 | - * @return array|null | |
| 40 | - */ | |
| 41 | - public function getBody() | |
| 42 | -    { | |
| 43 | - return $this->body; | |
| 44 | - } | |
| 38 | + /** | |
| 39 | + * @return array|null | |
| 40 | + */ | |
| 41 | + public function getBody() | |
| 42 | +	{ | |
| 43 | + return $this->body; | |
| 44 | + } | |
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | |
| 48 | - /** | |
| 49 | - * @return string | |
| 50 | - */ | |
| 51 | - public function runInForeground() | |
| 52 | -    { | |
| 53 | - ob_start(); | |
| 48 | + /** | |
| 49 | + * @return string | |
| 50 | + */ | |
| 51 | + public function runInForeground() | |
| 52 | +	{ | |
| 53 | + ob_start(); | |
| 54 | 54 | |
| 55 | -        $this->getDI()->get("console")->handle( | |
| 56 | - $this->getBody() | |
| 57 | - ); | |
| 55 | +		$this->getDI()->get("console")->handle( | |
| 56 | + $this->getBody() | |
| 57 | + ); | |
| 58 | 58 | |
| 59 | - $contents = ob_get_contents(); | |
| 59 | + $contents = ob_get_contents(); | |
| 60 | 60 | |
| 61 | - ob_end_clean(); | |
| 61 | + ob_end_clean(); | |
| 62 | 62 | |
| 63 | - return $contents; | |
| 64 | - } | |
| 63 | + return $contents; | |
| 64 | + } | |
| 65 | 65 | } | 
| @@ -4,72 +4,72 @@ | ||
| 4 | 4 | |
| 5 | 5 | class System extends \Sid\Phalcon\Cron\Job | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * @var string | |
| 9 | - */ | |
| 10 | - protected $command; | |
| 7 | + /** | |
| 8 | + * @var string | |
| 9 | + */ | |
| 10 | + protected $command; | |
| 11 | 11 | |
| 12 | - /** | |
| 13 | - * @var string | |
| 14 | - */ | |
| 15 | - protected $output; | |
| 12 | + /** | |
| 13 | + * @var string | |
| 14 | + */ | |
| 15 | + protected $output; | |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** | |
| 20 | - * @param string $expression | |
| 21 | - * @param string $command | |
| 22 | - * @param string $output | |
| 23 | - */ | |
| 24 | - public function __construct($expression, $command, $output = null) | |
| 25 | -    { | |
| 26 | - parent::__construct($expression); | |
| 19 | + /** | |
| 20 | + * @param string $expression | |
| 21 | + * @param string $command | |
| 22 | + * @param string $output | |
| 23 | + */ | |
| 24 | + public function __construct($expression, $command, $output = null) | |
| 25 | +	{ | |
| 26 | + parent::__construct($expression); | |
| 27 | 27 | |
| 28 | - $this->command = $command; | |
| 29 | - $this->output = $output; | |
| 30 | - } | |
| 28 | + $this->command = $command; | |
| 29 | + $this->output = $output; | |
| 30 | + } | |
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | - /** | |
| 35 | - * @return string | |
| 36 | - */ | |
| 37 | - public function getCommand() | |
| 38 | -    { | |
| 39 | - return $this->command; | |
| 40 | - } | |
| 34 | + /** | |
| 35 | + * @return string | |
| 36 | + */ | |
| 37 | + public function getCommand() | |
| 38 | +	{ | |
| 39 | + return $this->command; | |
| 40 | + } | |
| 41 | 41 | |
| 42 | - /** | |
| 43 | - * @return string | |
| 44 | - */ | |
| 45 | - public function getOutput() | |
| 46 | -    { | |
| 47 | - return $this->output; | |
| 48 | - } | |
| 42 | + /** | |
| 43 | + * @return string | |
| 44 | + */ | |
| 45 | + public function getOutput() | |
| 46 | +	{ | |
| 47 | + return $this->output; | |
| 48 | + } | |
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** | |
| 53 | - * @return string | |
| 54 | - */ | |
| 55 | - private function buildCommand() | |
| 56 | -    { | |
| 57 | - $command = $this->getCommand(); | |
| 52 | + /** | |
| 53 | + * @return string | |
| 54 | + */ | |
| 55 | + private function buildCommand() | |
| 56 | +	{ | |
| 57 | + $command = $this->getCommand(); | |
| 58 | 58 | |
| 59 | -        if ($this->getOutput()) { | |
| 60 | - $command .= ' > ' . $this->getOutput() . ' 2>&1'; | |
| 61 | - } | |
| 59 | +		if ($this->getOutput()) { | |
| 60 | + $command .= ' > ' . $this->getOutput() . ' 2>&1'; | |
| 61 | + } | |
| 62 | 62 | |
| 63 | - return $command; | |
| 64 | - } | |
| 63 | + return $command; | |
| 64 | + } | |
| 65 | 65 | |
| 66 | 66 | |
| 67 | 67 | |
| 68 | - /** | |
| 69 | - * @return string | |
| 70 | - */ | |
| 71 | - public function runInForeground() | |
| 72 | -    { | |
| 73 | - return shell_exec($this->buildCommand()); | |
| 74 | - } | |
| 68 | + /** | |
| 69 | + * @return string | |
| 70 | + */ | |
| 71 | + public function runInForeground() | |
| 72 | +	{ | |
| 73 | + return shell_exec($this->buildCommand()); | |
| 74 | + } | |
| 75 | 75 | } | 
| @@ -57,7 +57,7 @@ | ||
| 57 | 57 | $command = $this->getCommand(); | 
| 58 | 58 | |
| 59 | 59 |          if ($this->getOutput()) { | 
| 60 | - $command .= ' > ' . $this->getOutput() . ' 2>&1'; | |
| 60 | + $command .= ' > '.$this->getOutput().' 2>&1'; | |
| 61 | 61 | } | 
| 62 | 62 | |
| 63 | 63 | return $command; | 
| @@ -4,43 +4,43 @@ | ||
| 4 | 4 | |
| 5 | 5 | class Callback extends \Sid\Phalcon\Cron\Job | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * @var callable | |
| 9 | - */ | |
| 10 | - protected $callback; | |
| 7 | + /** | |
| 8 | + * @var callable | |
| 9 | + */ | |
| 10 | + protected $callback; | |
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * @param string $expression | |
| 16 | - * @param callable $callback | |
| 17 | - */ | |
| 18 | - public function __construct($expression, callable $callback) | |
| 19 | -    { | |
| 20 | - parent::__construct($expression); | |
| 14 | + /** | |
| 15 | + * @param string $expression | |
| 16 | + * @param callable $callback | |
| 17 | + */ | |
| 18 | + public function __construct($expression, callable $callback) | |
| 19 | +	{ | |
| 20 | + parent::__construct($expression); | |
| 21 | 21 | |
| 22 | - $this->callback = $callback; | |
| 23 | - } | |
| 22 | + $this->callback = $callback; | |
| 23 | + } | |
| 24 | 24 | |
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * @return callable | |
| 29 | - */ | |
| 30 | - public function getCallback() | |
| 31 | -    { | |
| 32 | - return $this->callback; | |
| 33 | - } | |
| 27 | + /** | |
| 28 | + * @return callable | |
| 29 | + */ | |
| 30 | + public function getCallback() | |
| 31 | +	{ | |
| 32 | + return $this->callback; | |
| 33 | + } | |
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** | |
| 38 | - * @return mixed | |
| 39 | - */ | |
| 40 | - public function runInForeground() | |
| 41 | -    { | |
| 42 | - $contents = call_user_func($this->callback); | |
| 37 | + /** | |
| 38 | + * @return mixed | |
| 39 | + */ | |
| 40 | + public function runInForeground() | |
| 41 | +	{ | |
| 42 | + $contents = call_user_func($this->callback); | |
| 43 | 43 | |
| 44 | - return $contents; | |
| 45 | - } | |
| 44 | + return $contents; | |
| 45 | + } | |
| 46 | 46 | } | 
| @@ -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 | } | 
| @@ -48,7 +48,7 @@ | ||
| 48 | 48 | */ | 
| 49 | 49 | public function isRunning() | 
| 50 | 50 |      { | 
| 51 | -        $result = shell_exec(sprintf("ps %d", $this->getProcessID()) . " | grep -v '<defunct>'"); | |
| 51 | +        $result = shell_exec(sprintf("ps %d", $this->getProcessID())." | grep -v '<defunct>'"); | |
| 52 | 52 | |
| 53 | 53 |          return (count(preg_split("/\n/", $result)) > 2); | 
| 54 | 54 | } |