diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index d67e3de..0000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -engines: - duplication: - enabled: true - config: - languages: - - javascript - - php - fixme: - enabled: true - phpmd: - enabled: true - checks: - Controversial/CamelCaseParameterName: - enabled: false - Controversial/CamelCasePropertyName: - enabled: false - Controversial/CamelCaseVariableName: - enabled: false - Naming/LongVariable: - enabled: false - Naming/ShortVariable: - enabled: false -ratings: - paths: - - "**.js" - - "**.php" -exclude_paths: [] diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..77a41d2 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: composer + directory: / + schedule: + interval: weekly + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..c5036a0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,44 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + +permissions: + contents: read + +jobs: + checks: + name: Checks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + # Run on the minimum supported PHP so php-cs-fixer doesn't suggest newer functions + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + extensions: pcntl, posix + - run: composer update --no-interaction --no-progress + - run: composer check + - run: composer audit --no-dev + + analyse: + name: PHPStan (PHP ${{ matrix.php }}${{ matrix.dependencies == 'lowest' && ', lowest deps' || '' }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ['8.2', '8.3', '8.4', '8.5'] + dependencies: [highest] + include: + - php: '8.2' + dependencies: lowest + steps: + - uses: actions/checkout@v7 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: pcntl, posix + - run: composer update --no-interaction --no-progress ${{ matrix.dependencies == 'lowest' && '--prefer-lowest' || '' }} + - run: composer phpstan diff --git a/.github/workflows/grumphp.yml b/.github/workflows/grumphp.yml deleted file mode 100644 index e96457f..0000000 --- a/.github/workflows/grumphp.yml +++ /dev/null @@ -1,39 +0,0 @@ -name: GrumPHP -on: push - -jobs: - grumphp: - runs-on: ubuntu-latest - strategy: - matrix: - php_version: - - '7.2' - - '7.3' - - '7.4' - steps: - - uses: actions/checkout@v2 - - name: Cache Composer Cache - uses: actions/cache@v2 - with: - path: ~/.composer/cache - key: ${{ runner.os }}-build-composer-cache-${{ matrix.php_version }}-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-build-composer-cache-${{ matrix.php_version }}- - ${{ runner.os }}-build-composer-cache- - ${{ runner.os }}- - - name: Install PHP - run: | - sudo add-apt-repository ppa:ondrej/php -y - sudo apt-get update - sudo apt-get install php${{ matrix.php_version }} - - name: Install Composer - run: | - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" - php -r "if (hash_file('sha384', 'composer-setup.php') === 'e5325b19b381bfd88ce90a5ddb7823406b2a38cff6bb704b0acc289a09c8128d4a8ce2bbafcd1fcbdc38666422fe2806') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" - php composer-setup.php - php -r "unlink('composer-setup.php');" - - name: Composer install - run: php composer.phar install - - name: GrumPHP - run: | - vendor/bin/grumphp run diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 6ff85d5..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: Lint -on: push - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Super-Linter - uses: docker://github/super-linter:v3 diff --git a/.gitignore b/.gitignore index bf6490a..9b7e79f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /vendor/ /composer.lock /sonar-project.properties -.php_cs.cache +.php-cs-fixer.cache diff --git a/.php_cs b/.php-cs-fixer.dist.php similarity index 91% rename from .php_cs rename to .php-cs-fixer.dist.php index bb74c80..2990e48 100644 --- a/.php_cs +++ b/.php-cs-fixer.dist.php @@ -32,7 +32,7 @@ $finder->exclude('data'); $finder->in(__DIR__); -$config = Config::create(); +$config = new Config(); $config->setRiskyAllowed(true); @@ -43,14 +43,13 @@ 'array_indentation' => true, 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => true, - 'blank_line_after_opening_tag' => true, + 'blank_line_after_opening_tag' => false, 'blank_line_before_statement' => [ 'statements' => [ 'case', 'continue', 'declare', 'default', - 'die', 'do', 'exit', 'for', @@ -66,10 +65,10 @@ ], ], 'cast_spaces' => ['space' => 'none'], - 'class_attributes_separation' => ['elements' => ['method', 'property']], + 'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one']], 'combine_consecutive_issets' => true, 'combine_consecutive_unsets' => true, - 'compact_nullable_typehint' => true, + 'compact_nullable_type_declaration' => true, 'concat_space' => ['spacing' => 'one'], 'date_time_immutable' => true, 'declare_equal_normalize' => true, @@ -80,9 +79,9 @@ 'final_internal_class' => true, 'fopen_flag_order' => true, 'fopen_flags' => true, - 'fully_qualified_strict_types' => true, + 'fully_qualified_strict_types' => ['phpdoc_tags' => []], 'function_to_constant' => true, - 'function_typehint_space' => true, + 'type_declaration_spaces' => true, 'heredoc_indentation' => true, 'heredoc_to_nowdoc' => true, 'implode_call' => true, @@ -102,7 +101,7 @@ 'native_constant_invocation' => false, 'native_function_casing' => true, 'native_function_invocation' => false, - 'new_with_braces' => true, + 'new_with_parentheses' => true, 'no_alternative_syntax' => true, 'no_binary_string' => true, 'no_blank_lines_after_class_opening' => true, @@ -119,14 +118,13 @@ 'no_null_property_initialization' => true, 'no_php4_constructor' => true, 'no_short_bool_cast' => true, - 'no_short_echo_tag' => true, + 'echo_tag_syntax' => ['format' => 'long'], 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_around_offset' => true, 'no_superfluous_elseif' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_comma_in_singleline' => true, 'no_unneeded_control_parentheses' => true, - 'no_unneeded_curly_braces' => true, + 'no_unneeded_braces' => true, 'no_unneeded_final_method' => true, 'no_unreachable_default_argument_value' => true, 'no_unset_cast' => true, @@ -155,7 +153,7 @@ 'phpdoc_types' => true, 'pow_to_exponentiation' => true, 'protected_to_private' => true, - 'psr4' => true, + 'psr_autoloading' => true, 'random_api_migration' => true, 'return_assignment' => true, 'return_type_declaration' => true, @@ -163,7 +161,7 @@ 'semicolon_after_instruction' => true, 'short_scalar_cast' => true, 'simplified_null_return' => true, - 'single_blank_line_before_namespace' => true, + 'blank_lines_before_namespace' => true, 'single_class_element_per_statement' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, @@ -177,7 +175,7 @@ 'string_line_ending' => true, 'ternary_operator_spaces' => true, 'ternary_to_null_coalescing' => true, - 'trailing_comma_in_multiline_array' => true, + 'trailing_comma_in_multiline' => true, 'unary_operator_spaces' => true, 'whitespace_after_comma_in_array' => true, ] diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b7c7076..0000000 --- a/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: php -php: - - 7.2 - - 7.3 - - 7.4 - - nightly -before_script: - - composer install - -script: - - vendor/bin/grumphp run - -matrix: - allow_failures: - - php: nightly diff --git a/README.md b/README.md index 354aa2d..0ed4229 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ # QueueJitsu [![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors) -[![Build Status](https://travis-ci.org/Mezzle/queuejitsu.svg?branch=master)](https://travis-ci.org/Mezzle/queuejitsu) -[![Code Climate](https://codeclimate.com/github/Mezzle/queuejitsu/badges/gpa.svg)](https://codeclimate.com/github/Mezzle/queuejitsu) -[![Test Coverage](https://codeclimate.com/github/Mezzle/queuejitsu/badges/coverage.svg)](https://codeclimate.com/github/Mezzle/queuejitsu/coverage) +[![CI](https://github.com/Mezzle/queuejitsu/actions/workflows/ci.yml/badge.svg)](https://github.com/Mezzle/queuejitsu/actions/workflows/ci.yml) -QueueJitsu is a queueing system built on the concepts of php-resque-ex, but made to work in a modern environment +QueueJitsu is a queueing system built on the concepts of php-resque-ex, but made to work in a modern environment. It requires PHP 8.2 or later. Console integration is provided by [QueueJitsu CLI](https://packagist.org/packages/mez/queuejitsu-cli) diff --git a/composer.json b/composer.json index 6477e13..761b544 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "mez/queuejitsu", - "type": "library", "description": "A Modern Queueing System", "license": "MIT", + "type": "library", "authors": [ { "name": "Martin Meredith", @@ -10,52 +10,59 @@ } ], "require": { - "php": "^7.2 || ^8.0", + "php": "^8.2", "ext-json": "*", - "ext-pcntl": "^7.2", - "ext-posix": "^7.2", - "laminas/laminas-eventmanager": "^3.2", - "predis/predis": "^1.1", - "psr/container": "^1.0", - "psr/log": "^1.0", - "ramsey/uuid": "^3.7 || ^4.0" + "ext-pcntl": "*", + "ext-posix": "*", + "laminas/laminas-eventmanager": "^3.13", + "predis/predis": "^3.3", + "psr/container": "^1.1 || ^2.0", + "psr/log": "^1.1 || ^2.0 || ^3.0", + "ramsey/uuid": "^4.7" }, "require-dev": { - "ergebnis/composer-normalize": "^2.6", - "friendsofphp/php-cs-fixer": "~2", - "maglnet/composer-require-checker": "^2.1", - "nikic/php-parser": "^4.6", - "php-parallel-lint/php-parallel-lint": "^1.2", - "phpro/grumphp-shim": "^0.19.0", - "phpstan/phpstan": "^0.12.32", - "roave/security-advisories": "dev-master", - "sensiolabs/security-checker": "^6.0" + "ergebnis/composer-normalize": "^2.45", + "friendsofphp/php-cs-fixer": "^3.64", + "maglnet/composer-require-checker": "^4.7", + "phpstan/phpstan": "^2.1" + }, + "conflict": { + "psr/http-message": "<1.1" }, "suggest": { "ext-pcntl": "Allows Workers to be ran in forked processes", "mez/queuejitsu-cli": "Command Line integration", "predis/predis": "Connect up to Redis" }, + "autoload": { + "psr-4": { + "QueueJitsu\\": "src" + } + }, "config": { - "optimize-autoloader": true, - "preferred-install": { - "stickee/*": "source", - "*": "dist" + "allow-plugins": { + "ergebnis/composer-normalize": true }, + "optimize-autoloader": true, "sort-packages": true }, "extra": { - "zf": { + "laminas": { "config-provider": "QueueJitsu\\ConfigProvider" } }, - "autoload": { - "psr-4": { - "QueueJitsu\\": "src" - } - }, "scripts": { - "cs-check": "php-cs-fixer --allow-risky=yes --config=.php_cs --dry-run --verbose fix", - "cs-fix": "php-cs-fixer --allow-risky=yes --config=.php_cs --verbose fix" + "check": [ + "@composer validate --strict", + "@normalize-check", + "@cs-check", + "@phpstan", + "@require-check" + ], + "cs-check": "php-cs-fixer check --diff --verbose", + "cs-fix": "php-cs-fixer fix --verbose", + "normalize-check": "@composer normalize --dry-run --indent-size=2 --indent-style=space", + "phpstan": "phpstan analyse", + "require-check": "composer-require-checker check composer.json" } } diff --git a/grumphp.yml b/grumphp.yml deleted file mode 100644 index 50d397e..0000000 --- a/grumphp.yml +++ /dev/null @@ -1,39 +0,0 @@ -grumphp: - tasks: - composer: - metadata: - priority: 1 - composer_normalize: - indent_size: 2 - indent_style: "space" - metadata: - priority: 0 - composer_require_checker: - metadata: - priority: 1 - jsonlint: - metadata: - priority: 2 - phpcsfixer2: - config: .php_cs - allow_risky: true - phplint: - metadata: - priority: 2 - phpstan: - metadata: - priority: 0 - level: 8 - phpversion: - project: '7.2' - metadata: - priority: 3 - securitychecker: - metadata: - priority: 3 - xmllint: - metadata: - priority: 2 - yamllint: - metadata: - priority: 2 diff --git a/phpstan.neon b/phpstan.neon index c8d2dbc..ce90f4b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,2 +1,6 @@ parameters: - checkMissingIterableValueType: false + level: 8 + paths: + - src + ignoreErrors: + - identifier: missingType.iterableValue diff --git a/src/Job/Adapter/RedisAdapter.php b/src/Job/Adapter/RedisAdapter.php index 2227527..7f057e5 100644 --- a/src/Job/Adapter/RedisAdapter.php +++ b/src/Job/Adapter/RedisAdapter.php @@ -42,7 +42,7 @@ class RedisAdapter implements StatusQueryInterface /** * @var \Predis\Client $client */ - private $client; + private Client $client; /** * RedisAdapter constructor. @@ -69,7 +69,7 @@ public function createFailure( string $queue ): void { $data = []; - $data['failed_at'] = strftime('%a %b %d %H:%M:%S %Z %Y'); + $data['failed_at'] = date('D M d H:i:s T Y'); $data['payload'] = $payload; $data['exception'] = get_class($exception); $data['error'] = $exception->getMessage(); @@ -119,6 +119,10 @@ public function getStatus(string $guid): array $status_packet = $this->client->get($key); + if (is_null($status_packet)) { + return []; + } + return json_decode($status_packet, true); } diff --git a/src/Job/Job.php b/src/Job/Job.php index 79d9301..c1a9e0c 100644 --- a/src/Job/Job.php +++ b/src/Job/Job.php @@ -38,27 +38,27 @@ class Job /** * @var array $args */ - private $args; + private array $args; /** * @var string $class */ - private $class; + private string $class; /** * @var string $id */ - private $id; + private string $id; /** * @var string $queue */ - private $queue; + private string $queue; /** * @var string $worker */ - private $worker; + private string $worker; /** * Job constructor. @@ -74,7 +74,7 @@ public function __construct( string $class, string $queue, array $args = [], - string $id = null + ?string $id = null ) { $this->class = $class; $this->args = $args; diff --git a/src/Job/JobManager.php b/src/Job/JobManager.php index ebaff4b..1671524 100644 --- a/src/Job/JobManager.php +++ b/src/Job/JobManager.php @@ -46,33 +46,33 @@ class JobManager implements EventManagerAwareInterface { use EventManagerAwareTrait; - const COMPLETED_STATUSES = [ + public const COMPLETED_STATUSES = [ self::STATUS_FAILED, self::STATUS_COMPLETE, ]; - const STATUS_COMPLETE = 4; + public const STATUS_COMPLETE = 4; - const STATUS_FAILED = 3; + public const STATUS_FAILED = 3; - const STATUS_RUNNING = 2; + public const STATUS_RUNNING = 2; - const STATUS_WAITING = 1; + public const STATUS_WAITING = 1; /** * @var \QueueJitsu\Job\Adapter\AdapterInterface $adapter */ - private $adapter; + private AdapterInterface $adapter; /** * @var \Psr\Log\LoggerInterface $log */ - private $log; + private LoggerInterface $log; /** * @var \QueueJitsu\Job\Strategy\StrategyInterface $strategy */ - private $strategy; + private StrategyInterface $strategy; /** * JobManager constructor. @@ -115,7 +115,7 @@ public function run(Job $job): void if (!$jobInstance instanceof HasTearDown && method_exists($jobInstance, 'tearDown')) { throw new Deprecated( - 'Use of setUp function without \QueueJitsu\Job\HasTearDown Interface is deprecated' + 'Use of tearDown function without \QueueJitsu\Job\HasTearDown Interface is deprecated' ); } @@ -206,7 +206,7 @@ public function enqueue(Job $job): void * * @return array */ - public function getStatus(string $guid) + public function getStatus(string $guid): array { if ($this->adapter instanceof StatusQueryInterface) { return $this->adapter->getStatus($guid); diff --git a/src/Job/JobManagerFactory.php b/src/Job/JobManagerFactory.php index 2d697cf..c3600f1 100644 --- a/src/Job/JobManagerFactory.php +++ b/src/Job/JobManagerFactory.php @@ -47,7 +47,7 @@ class JobManagerFactory * * @return \QueueJitsu\Job\JobManager */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): JobManager { $logger_class = NullLogger::class; diff --git a/src/Job/Strategy/ContainerStrategy.php b/src/Job/Strategy/ContainerStrategy.php index eea57ff..1aa9b44 100644 --- a/src/Job/Strategy/ContainerStrategy.php +++ b/src/Job/Strategy/ContainerStrategy.php @@ -38,7 +38,7 @@ class ContainerStrategy implements StrategyInterface /** * @var \Psr\Container\ContainerInterface $container */ - private $container; + private ContainerInterface $container; /** * ContainerStrategy constructor. diff --git a/src/Job/Strategy/ContainerStrategyFactory.php b/src/Job/Strategy/ContainerStrategyFactory.php index 0f661ba..95f04a3 100644 --- a/src/Job/Strategy/ContainerStrategyFactory.php +++ b/src/Job/Strategy/ContainerStrategyFactory.php @@ -42,7 +42,7 @@ class ContainerStrategyFactory * * @return \QueueJitsu\Job\Strategy\ContainerStrategy */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): ContainerStrategy { return new ContainerStrategy($container); } diff --git a/src/Queue/Adapter/RedisAdapter.php b/src/Queue/Adapter/RedisAdapter.php index cb398bb..7b5e78c 100644 --- a/src/Queue/Adapter/RedisAdapter.php +++ b/src/Queue/Adapter/RedisAdapter.php @@ -39,7 +39,7 @@ class RedisAdapter implements AdapterInterface /** * @var \Predis\Client $client */ - private $client; + private Client $client; /** * RedisAdapter constructor. @@ -58,13 +58,7 @@ public function __construct(Client $client) */ public function getAllQueueNames(): array { - $queues = $this->client->smembers('queue'); - - if (!is_array($queues)) { - $queues = []; - } - - return $queues; + return $this->client->smembers('queue'); } /** diff --git a/src/Queue/QueueManager.php b/src/Queue/QueueManager.php index 633cf1c..f976bd6 100644 --- a/src/Queue/QueueManager.php +++ b/src/Queue/QueueManager.php @@ -40,17 +40,17 @@ class QueueManager /** * @var \QueueJitsu\Queue\Adapter\AdapterInterface $adapter */ - private $adapter; + private AdapterInterface $adapter; /** * @var string[] $queues */ - private $queues; + private array $queues; /** * @var \QueueJitsu\Queue\Strategy\StrategyInterface $strategy */ - private $strategy; + private StrategyInterface $strategy; /** * QueueManager constructor. diff --git a/src/Queue/QueueManagerFactory.php b/src/Queue/QueueManagerFactory.php index 5842fe4..ede90f1 100644 --- a/src/Queue/QueueManagerFactory.php +++ b/src/Queue/QueueManagerFactory.php @@ -45,7 +45,7 @@ class QueueManagerFactory * * @return \Closure */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): callable { $strategy_class = $container->has(Strategy::class) ? Strategy::class : Simple::class; diff --git a/src/Queue/Strategy/Simple.php b/src/Queue/Strategy/Simple.php index f6bc6cd..a4ea7f7 100644 --- a/src/Queue/Strategy/Simple.php +++ b/src/Queue/Strategy/Simple.php @@ -40,7 +40,7 @@ class Simple implements StrategyInterface /** * @var \Psr\Log\LoggerInterface $log */ - private $log; + private LoggerInterface $log; /** * Simple constructor. diff --git a/src/Queue/Strategy/SimpleFactory.php b/src/Queue/Strategy/SimpleFactory.php index 36a986b..79c1a64 100644 --- a/src/Queue/Strategy/SimpleFactory.php +++ b/src/Queue/Strategy/SimpleFactory.php @@ -44,7 +44,7 @@ class SimpleFactory * * @return \QueueJitsu\Queue\Strategy\Simple */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): Simple { $logger_class = $container->has(LoggerInterface::class) ? LoggerInterface::class : diff --git a/src/Worker/AbstractWorker.php b/src/Worker/AbstractWorker.php index f17043e..dbb9ef0 100644 --- a/src/Worker/AbstractWorker.php +++ b/src/Worker/AbstractWorker.php @@ -43,47 +43,47 @@ abstract class AbstractWorker implements EventManagerAwareInterface /** * @var bool|null|int $child */ - protected $child; + protected bool|int|null $child = null; /** * @var bool $finish */ - protected $finish = false; + protected bool $finish = false; /** * @var string|false $hostname */ - protected $hostname; + protected string|false $hostname; /** * @var string $id */ - protected $id; + protected string $id; /** * @var int $interval */ - protected $interval = 5; + protected int $interval = 5; /** * @var \Psr\Log\LoggerInterface $log */ - protected $log; + protected LoggerInterface $log; /** * @var \QueueJitsu\Worker\WorkerManager $manager */ - protected $manager; + protected WorkerManager $manager; /** * @var bool $paused */ - protected $paused = false; + protected bool $paused = false; /** * @var string $worker_name */ - protected $worker_name; + protected string $worker_name; /** * AbstractWorker constructor. @@ -104,11 +104,11 @@ public function __construct(LoggerInterface $log, WorkerManager $manager) /** * __invoke * - * @param int $interval + * @param int|string $interval */ - public function __invoke($interval = 5): void + public function __invoke(int|string $interval = 5): void { - $this->interval = $interval; + $this->interval = (int)$interval; $this->updateProcLine('Starting'); $this->startup(); @@ -331,7 +331,7 @@ protected function finishedWorking(): void * * @return bool|int */ - protected function fork() + protected function fork(): bool|int { if (!function_exists('pcntl_fork')) { return false; @@ -352,7 +352,7 @@ protected function fork() * * @param mixed $data */ - protected function setTask($data): void + protected function setTask(mixed $data): void { $this->manager->setTask($this, $data); } diff --git a/src/Worker/Adapter/RedisAdapter.php b/src/Worker/Adapter/RedisAdapter.php index 15a57d8..980deb9 100644 --- a/src/Worker/Adapter/RedisAdapter.php +++ b/src/Worker/Adapter/RedisAdapter.php @@ -39,7 +39,7 @@ class RedisAdapter implements AdapterInterface /** * @var \Predis\Client $client */ - private $client; + private Client $client; /** * RedisAdapter constructor. @@ -68,13 +68,7 @@ public function clearTaskData(AbstractWorker $worker): void */ public function getAllWorkerIds(): array { - $workers = $this->client->smembers('workers'); - - if (!is_array($workers)) { - $workers = []; - } - - return $workers; + return $this->client->smembers('workers'); } /** @@ -105,7 +99,7 @@ public function registerWorker(string $worker): void $this->client->sadd('workers', [$worker]); $this->client->set( sprintf('worker:%s:started', $worker), - strftime('%a %b %d %H:%M:%S %Z %Y') + date('D M d H:i:s T Y') ); } diff --git a/src/Worker/Worker.php b/src/Worker/Worker.php index 5dd9957..177ff13 100644 --- a/src/Worker/Worker.php +++ b/src/Worker/Worker.php @@ -42,17 +42,12 @@ class Worker extends AbstractWorker /** * @var \QueueJitsu\Job\JobManager $job_manager */ - protected $job_manager; + protected JobManager $job_manager; /** * @var \QueueJitsu\Queue\QueueManager $queue_manager */ - protected $queue_manager; - - /** - * @var Job|null $current_job - */ - private $current_job; + protected QueueManager $queue_manager; /** * Worker constructor. @@ -84,16 +79,6 @@ protected function getWorkerIdentifier(): string return implode(',', $this->queue_manager->getQueues()); } - /** - * finishedWorking - */ - protected function finishedWorking(): void - { - $this->current_job = null; - - parent::finishedWorking(); - } - /** * loop * @@ -150,12 +135,11 @@ private function setWorkingOn(Job $job): void $this->setTask( [ 'queue' => $job->getQueue(), - 'run_at' => strftime('%a %b %d %H:%M:%S %Z %Y'), + 'run_at' => date('D M d H:i:s T Y'), 'payload' => $job->getPayload(), ] ); - $this->current_job = $job; $job->setWorker($this->getId()); $this->job_manager->updateStatus($job, JobManager::STATUS_RUNNING); } diff --git a/src/Worker/WorkerManager.php b/src/Worker/WorkerManager.php index 2352fac..e41c61d 100644 --- a/src/Worker/WorkerManager.php +++ b/src/Worker/WorkerManager.php @@ -39,17 +39,17 @@ class WorkerManager /** * @var \QueueJitsu\Worker\Adapter\AdapterInterface $adapter */ - private $adapter; + private AdapterInterface $adapter; /** * @var string|false $hostname */ - private $hostname; + private string|false $hostname; /** * @var \Psr\Log\LoggerInterface $log */ - private $log; + private LoggerInterface $log; /** * WorkerManager constructor. @@ -141,7 +141,7 @@ public function registerWorker(string $worker): void * @param \QueueJitsu\Worker\AbstractWorker $worker * @param mixed $data */ - public function setTask(AbstractWorker $worker, $data): void + public function setTask(AbstractWorker $worker, mixed $data): void { $this->adapter->setTask($worker, $data); } diff --git a/src/Worker/WorkerManagerFactory.php b/src/Worker/WorkerManagerFactory.php index 626f84c..01bc89c 100644 --- a/src/Worker/WorkerManagerFactory.php +++ b/src/Worker/WorkerManagerFactory.php @@ -45,7 +45,7 @@ class WorkerManagerFactory * * @return \QueueJitsu\Worker\WorkerManager */ - public function __invoke(ContainerInterface $container) + public function __invoke(ContainerInterface $container): WorkerManager { $logger_class = $container->has(Logger::class) ? Logger::class : NullLogger::class;