public function testStopListeningRemovesListener() { $callback = 'beforePerformEventCallback'; $event = 'beforePerform'; Event::listen($event, array($this, $callback)); Event::stopListening($event, array($this, $callback)); $job = $this->getEventTestJob(); $this->worker->perform($job); $this->worker->work(0); $this->assertNotContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was called though Event::stopListening was called'); }
<?php require_once __DIR__ . '/../autoload.php'; use resque\core\Event; // Somewhere in our application, we need to register: Event::listen('afterEnqueue', array('ResquePlugin', 'afterEnqueue')); Event::listen('beforeFirstFork', array('ResquePlugin', 'beforeFirstFork')); Event::listen('beforeFork', array('ResquePlugin', 'beforeFork')); Event::listen('afterFork', array('ResquePlugin', 'afterFork')); Event::listen('beforePerform', array('ResquePlugin', 'beforePerform')); Event::listen('afterPerform', array('ResquePlugin', 'afterPerform')); Event::listen('onFailure', array('ResquePlugin', 'onFailure')); class ResquePlugin { public static function afterEnqueue($class, $arguments) { echo "Job was queued for " . $class . ". Arguments:"; print_r($arguments); } public static function beforeFirstFork($worker) { echo "Worker started. Listening on queues: " . implode(', ', $worker->queues(false)) . "\n"; } public static function beforeFork($job) { echo "Just about to fork to run " . $job; } public static function afterFork($job) { echo "Forked to run " . $job . ". This is the child process.\n"; }