daycry/queues

Queues for Codeigniter 4

v2.0.14 2024-12-04 15:07 UTC

README

Donate

Queues for Codeigniter 4

Codeigniter 4 with beanstalk, redis, sync & service bus (azure) queues

Build status Coverage status Downloads GitHub release (latest by date) GitHub stars GitHub license

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);