Resque\Event::fire PHP Method

fire() public static method

Raise a given event with the supplied data.
public static fire ( string $event, mixed $data = null ) : true
$event string Name of event to be raised
$data mixed Data that should be passed to each callback (optional)
return true
    public static function fire($event, $data = null)
    {
        if (!is_array($data)) {
            $data = array($data);
        }
        array_unshift($data, $event);
        $retval = true;
        foreach (array('*', $event) as $e) {
            if (!array_key_exists($e, self::$events)) {
                continue;
            }
            foreach (self::$events[$e] as $callback) {
                if (!is_callable($callback)) {
                    continue;
                }
                if (($retval = call_user_func_array($callback, $data)) === false) {
                    break 2;
                }
            }
        }
        return $retval !== false;
    }

Usage Example

Example #1
0
 /**
  * Mark the current job as having failed
  * 
  * @param \Exception $e
  */
 public function fail(\Exception $e)
 {
     $this->stopped();
     $this->setStatus(Job::STATUS_FAILED, $e);
     // For the failed jobs we store a lot more data for debugging
     $packet = $this->getPacket();
     $failed_payload = array_merge(json_decode($this->payload, true), array('worker' => $packet['worker'], 'started' => $packet['started'], 'finished' => $packet['finished'], 'output' => $packet['output'], 'exception' => (array) json_decode($packet['exception'], true)));
     $this->redis->zadd(Queue::redisKey($this->queue, 'failed'), time(), json_encode($failed_payload));
     Stats::incr('failed', 1);
     Stats::incr('failed', 1, Queue::redisKey($this->queue, 'stats'));
     Event::fire(Event::JOB_FAILURE, array($this, $e));
 }
All Usage Examples Of Resque\Event::fire