Codeigniter 4 with beanstalk, redis, sync & service bus (azure) queues
Use the package with composer install
> composer require daycry/queues
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
| Tasks |
|---|
| url |
| command |
| classes |
| shell |
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');$dateTimeObj= new DateTime('now');
$dateTimeObj->add(new DateInterval("PT1H"));
$job = new Job();
$job->shell('ls');
$job->scheduled($dateTimeObj);
$result = $job->enqueue('default');You can configure a callback using 'URL' type.
$job->setCallback('https://httpbin.org/post', ['method' => 'post', 'headers' =>['X-API-KEY' => '1234']]);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');> 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);