daycry / queues
Queues for Codeigniter 4
Requires
- php: ^8.0
- codeigniter4/settings: ^2.2
- daycry/exceptions: ^1.0
- guzzlehttp/guzzle: ^7.8
- pda/pheanstalk: ^5.0
- supervisorphp/supervisor: ^5.1
Requires (Dev)
- angelov/phpunit-php-vcr: ^1.1
- codeigniter/phpstan-codeigniter: ^1.3
- codeigniter4/devkit: *
- codeigniter4/framework: ^4
- mikey179/vfsstream: ^1.6.7
- mockery/mockery: ^1.0
- php-vcr/php-vcr: ^1.7
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpunit/phpcov: ^9.0.2
- rector/rector: 1.2.1
README
Queues for Codeigniter 4
Codeigniter 4 with beanstalk, redis, sync & service bus (azure) queues
Installation via composer
Use the package with composer install
> composer require daycry/queues
Configuration
Run command:
> php spark queues:publish
This command will copy a config file to your app namespace.
Then you can adjust it to your needs. By default file will be present in app/Config/Queue.php
.
Allowed tasks
Usage Job Class
URL
use Daycry\Queues\Job; $job = new Job(); $job = $job->setQueue('default') ->url('https://httpbin.org/post', [ 'verify' => false, 'method' => 'post', 'body' => ['param1' => 'p1'], 'dataType' => 'json', 'headers' => [ 'X-API-KEY' => '1234' ] ) ->enqueue();
COMMAND
use Daycry\Queues\Job; $job = new Job(); $job = $job->command('foo:bar')->enqueue('default');
CLASSES
use Daycry\Queues\Job; $job = new Job(); $job->classes(\Tests\Support\Classes\Example::class, 'run', ['constructor' => 'Contructor', 'method' => ['param1' => 1, 'param2' => 2]])->enqueue('default');
You can pass options in third parameter that contains paraterms in construct function and/or method.
SHELL
use Daycry\Queues\Job; $job = new Job(); $job->shell('ls')->enqueue('default');
Job Scheduled
$dateTimeObj= new DateTime('now'); $dateTimeObj->add(new DateInterval("PT1H")); $job = new Job(); $job->shell('ls'); $job->scheduled($dateTimeObj); $result = $job->enqueue('default');
Job Callback
You can configure a callback using 'URL' type.
$job->setCallback('https://httpbin.org/post', ['method' => 'post', 'headers' =>['X-API-KEY' => '1234']]);
Custom Methods
Beanstalk and Service Bus have custom methods
BEANSTALK
use Daycry\Queues\Job; $job = new Job(); $job->shell('ls')->setPriority(10)->setTtr(3600)->enqueue('default');
SERVICE BUS
use Daycry\Queues\Job; $job = new Job(); $job->shell('ls')->setLabel('label')->enqueue('default');
Usage Worker
> cd /path-to-your-project && php spark queues:worker default
On default is the name of queue.
If you want to execute only one time the worker, you can do this:
> cd /path-to-your-project && php spark queues:worker default --oneTime
In order to use these functions, the class must be extended.
You can extends the worker command for customize early and late methods.
use Daycry\Queues\Job; $this->earlyChecks(Job $j); //job execution $this->lateChecks($j); $this->earlyCallbackChecks(Job $j); //callback execution $this->lateCallbackChecks($j);