diff --git a/CHANGELOG.md b/CHANGELOG.md index 203d10a..4e628f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.4.3 (2018-07-16) +- Updated README to include supervisor configuration. +- Change logfile date format to `%Y-%m-%d %T`. +- Added return types to more functions. + ## 1.4.2 (2018-05-30) - Reimplemented credis due to issues with Redis: Connection Closed. - Updated Docs. @@ -14,7 +19,6 @@ - Replaced credis in favour of phpredis. - Reformatted codebase to be PSR2 compliant. - ## 1.3 (2013) **Note:** This release introduces backwards incompatible changes with all previous versions of php-resque. Please see below for details. diff --git a/README.md b/README.md index 7bc468f..acac87b 100644 --- a/README.md +++ b/README.md @@ -432,6 +432,30 @@ Called after a job has been queued using the `Resque::enqueue` method. Arguments * Queue - string containing the name of the queue the job was added to * ID - string containing the new token of the enqueued job +## Supervisor Configuration ## + +You may like to run php-resque on a supervisor task to manage the processes. +The following is a default config that can be modified to suit. + +```sh +[program:resque-dev] +directory=/var/www # Project root +command=php vendor/bin/resque +numprocs=2 # Change this value for more threads +environment=LOGLEVEL=NOTICE,QUEUE='*',BLOCKING=1,COUNT=1,APP_INCLUDE='includes/autoload.php',REDIS_BACKEND=127.0.0.1,REDIS_BACKEND_DB=0 +redirect_stderr=true # Output stderr to logfile +stdout_logfile=/var/log/resque.log +autostart=true +autorestart=true +stopsignal=QUIT +process_name = %(program_name)s_%(process_num)02d +``` + +Issues: +- Restarting worker doesn't always make it use updated code, I find on a dev-environment issuing +the following command works well to restart everything. +`sudo /etc/init.d/supervisor force-stop && sleep 1 && sudo /etc/init.d/supervisor restart` + ## Step-By-Step ## For a more in-depth look at what php-resque does under the hood (without diff --git a/composer.json b/composer.json index 045bb40..e53bff1 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { "name": "idanoo/php-resque", - "version": "1.4.2", + "version": "1.4.3", "type": "library", "description": "Redis backed library for creating background jobs and processing them later. Based on resque for Ruby. Originally forked from chrisboulton/php-resque.", "keywords": ["job", "background", "redis", "resque"], - "homepage": "http://www.github.com/iDanoo/php-resque/", + "homepage": "http://www.github.com/idanoo/php-resque/", "license": "MIT", "authors": [ { @@ -19,9 +19,6 @@ "psr/log": "~1.0", "colinmollenhour/credis": "^1.10" }, - "suggest": { - "ext-proctitle": "Allows php-resque to rename the title of UNIX processes to show the status of a worker." - }, "require-dev": { "phpunit/phpunit": "^6" }, @@ -32,5 +29,9 @@ "psr-0": { "Resque": "lib" } + }, + "support": { + "issues": "https://github.com/idanoo/php-resque/issues", + "source": "https://github.com/idanoo/php-resque" } } diff --git a/lib/Resque.php b/lib/Resque.php index 222336f..a7bff07 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -1,4 +1,4 @@ -payload['id'])) { - return; + return false; } $statusInstance = new Resque_Job_Status($this->payload['id']); $statusInstance->update($status); + return true; } /** diff --git a/lib/Resque/Job/Status.php b/lib/Resque/Job/Status.php index 730677b..257e6df 100644 --- a/lib/Resque/Job/Status.php +++ b/lib/Resque/Job/Status.php @@ -66,7 +66,7 @@ class Resque_Job_Status * * @return boolean True if the status is being monitored, false if not. */ - public function isTracking() + public function isTracking(): bool { if ($this->isTracking === false) { return false; @@ -137,7 +137,7 @@ class Resque_Job_Status * * @return string String representation of the current job status class. */ - public function __toString() + public function __toString(): string { return 'job:' . $this->id . ':status'; } diff --git a/lib/Resque/Log.php b/lib/Resque/Log.php index 6735418..4182b23 100644 --- a/lib/Resque/Log.php +++ b/lib/Resque/Log.php @@ -27,15 +27,25 @@ class Resque_Log extends Psr\Log\AbstractLogger */ public function log($level, $message, array $context = []) { - $logLevels = ["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"]; + $logLevels = [ + "emergency", + "alert", + "critical", + "error", + "warning", + "notice", + "info", + "debug" + ]; + /** - * Only log things with a higher rating than the current log level. + * Only log things with a higher level than the current log level. * e.g If set as 'alert' will only alert for 'emergency' and 'alert' logs. */ if (array_search($level, $logLevels) <= array_search($this->logLevel, $logLevels)) { fwrite( STDOUT, - '[' . $level . '][' . strftime('%T %Y-%m-%d') . '] ' . $this->interpolate($message, $context) . PHP_EOL + '[' . $level . '][' . strftime('%Y-%m-%d %T') . '] ' . $this->interpolate($message, $context) . PHP_EOL ); } return; diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index 169e010..ee21223 100644 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -252,12 +252,12 @@ class Resque_Redis } } - public static function getPrefix() + public static function getPrefix(): string { return self::$defaultNamespace; } - public static function removePrefix($string) + public static function removePrefix($string): string { $prefix = self::getPrefix(); diff --git a/lib/Resque/Stat.php b/lib/Resque/Stat.php index 9855638..0cca826 100644 --- a/lib/Resque/Stat.php +++ b/lib/Resque/Stat.php @@ -16,7 +16,7 @@ class Resque_Stat * @param string $stat The name of the statistic to get the stats for. * @return mixed Value of the statistic. */ - public static function get($stat) + public static function get($stat): int { return (int)Resque::redis()->get('stat:' . $stat); } @@ -28,7 +28,7 @@ class Resque_Stat * @param int $by The amount to increment the statistic by. * @return boolean True if successful, false if not. */ - public static function incr($stat, $by = 1) + public static function incr($stat, $by = 1): bool { return (bool)Resque::redis()->incrby('stat:' . $stat, $by); } @@ -40,7 +40,7 @@ class Resque_Stat * @param int $by The amount to decrement the statistic by. * @return boolean True if successful, false if not. */ - public static function decr($stat, $by = 1) + public static function decr($stat, $by = 1): bool { return (bool)Resque::redis()->decrby('stat:' . $stat, $by); } @@ -51,7 +51,7 @@ class Resque_Stat * @param string $stat The name of the statistic to delete. * @return boolean True if successful, false if not. */ - public static function clear($stat) + public static function clear($stat): bool { return (bool)Resque::redis()->del('stat:' . $stat); } diff --git a/lib/Resque/Worker.php b/lib/Resque/Worker.php index d7a7aa9..d4e385b 100644 --- a/lib/Resque/Worker.php +++ b/lib/Resque/Worker.php @@ -82,7 +82,7 @@ class Resque_Worker * Return all workers known to Resque as instantiated instances. * @return array */ - public static function all() + public static function all(): array { $workers = Resque::redis()->smembers('workers'); if (!is_array($workers)) { @@ -103,7 +103,7 @@ class Resque_Worker * @return boolean True if the worker exists, false if not. * @throws Resque_RedisException */ - public static function exists($workerId) + public static function exists($workerId): bool { return (bool)Resque::redis()->sismember('workers', $workerId); } @@ -532,14 +532,10 @@ class Resque_Worker * * @return array Array with details of current job. */ - public function job() + public function job(): array { $job = Resque::redis()->get('worker:' . $this); - if (!$job) { - return []; - } else { - return json_decode($job, true); - } + return $job ? json_decode($job, true) : []; } /**