mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-24 01:05:13 +00:00
- Updated README to include supervisor configuration.
- Change logfile date format to `%Y-%m-%d %T`. - Added return types to more functions.
This commit is contained in:
parent
f69330d637
commit
4e87677517
@ -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.
|
||||
|
24
README.md
24
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
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php /** @noinspection ALL */
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Base Resque class.
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
class Resque
|
||||
{
|
||||
const VERSION = '1.4.2';
|
||||
const VERSION = '1.4.3';
|
||||
|
||||
const DEFAULT_INTERVAL = 5;
|
||||
|
||||
|
@ -124,14 +124,15 @@ class Resque_Job
|
||||
*
|
||||
* @param int $status Status constant from Resque_Job_Status indicating the current status of a job.
|
||||
*/
|
||||
public function updateStatus($status)
|
||||
public function updateStatus($status): bool
|
||||
{
|
||||
if (empty($this->payload['id'])) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$statusInstance = new Resque_Job_Status($this->payload['id']);
|
||||
$statusInstance->update($status);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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';
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user