PHP code example of hirale / queue

1. Go to this page and download the library: Download hirale/queue library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

hirale / queue example snippets


  use Hirale\Queue\Bus;
  Bus::dispatch(new DrainEventsMessage(reason: 'index_events'));
  


use Hirale\Queue\Bus;

class Hirale_AsyncIndex_Helper_Data extends Mage_Core_Helper_Abstract
{
    public function scheduleDrain(string $reason): void
    {
        Bus::dispatch(new Hirale_AsyncIndex_Message_DrainEventsMessage(
            reason: $reason,
            entity: 'catalog_product',
        ));
    }
}

// Route this dispatch to a non-default queue.
Bus::dispatchOnQueue($message, 'full_reindex');

// Delay the first attempt by N seconds.
Bus::dispatchDelayed($message, 60);



class Hirale_AsyncIndex_Model_DrainEventsHandler
{
    public function __invoke(Hirale_AsyncIndex_Message_DrainEventsMessage $message): void
    {
        // Do the work. Throwing reschedules per the retry policy.
        Mage::getModel('hirale_asyncindex/runner')->drain($message->reason);
    }
}
bash
php shell/hirale_queue_worker.php --queues default
bash
./maho hirale:queue:consume default full_reindex \
    --time-limit=3600 \
    --limit=10000 \
    --sleep=1 \
    --memory-limit=512 \
    --consumer=hirale_worker_01
ini
[job-exec "maho-queue-worker"]
schedule = @every 1m
container = php-fpm
command = php /var/www/maho/maho hirale:queue:consume default --time-limit=3540 --memory-limit=256
user = www-data
tty = false
no-overlap = true