A simple queue processor wrote in PHP simple and fast. (Work in progress)
id | channel | action | data | status | tries | after |
---|---|---|---|---|---|---|
1 | payment | MyApp\Sales\Payment::process | { "var": 12 } | 0 | 1 | 6542134421 |
2 | payment | Payment:payment | { "var": 12 } | 1 | 1 | 6542134421 |
data: json variables(no complex objects)
status: 1 = Processed | 0 = Holding | 2 - Failed
after: unixtimestamp (when to execute)
- Read Queue = Collection
- Process Queue = execute the list
- Read Queue = List all activities
- Clear Queue = Clear processed actions(soft delete?)
- Trash Queue = Delete all processed action
<?php
$adapter = new FastQ\Adapters\Mysql(new PDO('...', 'user', 'pass'));
// Instanciate with dependency
$queue = new FastQ\Queue($adapter);
// Container callable
$queue->push('payment', 'Payment:process', '+5 seconds')->withData([
'paymentId' => 'PAY-4880903345'
]);
// Static callable
$queue->push('payment', 'MyApp\\Payment::sendSMS', '+5 seconds')->withData([
'paymentId' => 'PAY-4880903345'
]);
// Container Invokable call($receiver->__invoke())
$queue->push('payment', 'Receiver', '+5 seconds')->withData([
'paymentId' => 'PAY-4880903345'
]);
$ php vendor/bin/fastq init
$ php vendor/bin/fastq dump
$ php vendor/bin/fastq dump sqlite
$ php vendor/bin/fastq work
$ php vendor/bin/fastq work --listen
<?php
$adapter = new FastQ\Adapters\Mysql(new PDO('...', 'user', 'pass'));
// Instanciate with dependency
$queue = new FastQ\Queue($adapter);
$worker = $queue->pull('channelName');
// Execute the jobs
$worker->run();
// Response completed
var_dump($worker->getCompleted());
// Response failures
var_dump($worker->getFailures());
Make the consumer/worker commands How to implement async in Worker.php? ReactPHP?
Leonardo Tumadjian