php-queuesadilla :: index

Callbacks

Queuesadilla allows developers to hook into various events in the queue/work cycle using the league/event package. To do so, you can attach a listener to the object as follows:

<?php
use League\Event\AbstractEvent;
$object = new ClassThatEmitsEvents;
// Using a callable
$object->attachListener($event, function (AbstractEvent $event) {
    // Your Work Here
});

// Using a class
$object->attachListener(new ClassBasedListener);
?>

The AbstractEvent $event object that is passed in will always be an instance of the josegonzalez\Queuesadilla\Event\Event class, which has the ability the following helper methods:

You can otherwise interact with the events as you normally would with league/event package. Please consult those docs for more information.

Creating Class Based Listeners

There are two ways to create class-based listeners. The simplest way would be to create a class that extends League\Event\AbstractEvent:

<?php
use League\Event\AbstractListener;
use League\Event\AbstractEvent;

class StatsListener extends AbstractListener
{
    public function handle(AbstractEvent $event)
    {
        // do your worst here
    }
}
?>

You can also create a listener that can bind to multiple events by extending the josegonzalez\Queuesadilla\Event\MultiEventListener class:

<?php
use josegonzalez\Queuesadilla\Event\MultiEventListener;
use League\Event\AbstractEvent;

class StatsListener extends MultiEventListener
{
    public function implementedEvents()
    {
        return [
            'an.event' => 'aFunction',
            'another.event' => 'anotherFunction',
        ];
    }

    public function aFunction(AbstractEvent $event)
    {
        // do your worst here
    }

    public function anotherFunction(AbstractEvent $event)
    {
        // do your worst here
    }
}
?>

Available Events

Queuing

When queuing a job, you have the ability to hook into the following events:

Worker

When processing jobs via a worker, you have the ability to hook into the following events: