Example #1
0
 /**
  * Process the job
  *
  * @param Job $job
  */
 public function process(Job $job)
 {
     $job->active();
     $job->set('worker', $this->id);
     try {
         $start = Util::now();
         $this->queue->emit('process:' . $job->type, $job);
         // Retry when failed
         if ($job->state == 'failed') {
             throw new AttemptException("failed to attempts");
         }
         $duration = Util::now() - $start;
         $job->complete();
         $job->set('duration', $duration);
     } catch (\Exception $e) {
         if ($e instanceof AttemptException) {
             $e = null;
         }
         $this->failed($job, $e);
     }
 }
Example #2
0
 /**
  * Change state
  *
  * @param $state
  * @return $this
  */
 public function state($state)
 {
     $this->emit($state);
     $this->removeState();
     // Keep "FIFO!"
     $score = $this->injectors['timing'] + $this->injectors['priority'];
     $this->set('state', $state);
     $this->client->zadd('q:jobs', $score, $this->injectors['id']);
     $this->client->zadd('q:jobs:' . $state, $score, $this->injectors['id']);
     $this->client->zadd('q:jobs:' . $this->injectors['type'] . ':' . $state, $score, $this->injectors['id']);
     // Set inactive job to waiting list
     if ($this->queue->originalMode() && 'inactive' == $state) {
         $this->client->lpush('q:' . $this->injectors['type'] . ':jobs', 1);
     }
     $this->set('updated_at', Util::now());
     return $this;
 }
Example #3
0
<?php

/**
 * createQueue.php
 *
 * @package default
 */
include_once './vendor/autoload.php';
use Kue\Kue;
if (!class_exists('Kue\\Kue', true)) {
    die('Kue class not found..  composer require kue/kue');
}
$kue = Kue::createQueue(array('host' => 'beo.infinitumtech.net', 'port' => '8100'));
print 'connected to redis server..
	';
$queued = 0;
echo 'adding items to the queue...
';
while (1) {
    $newJob = array('title' => 'email job #' . $queued, 'to' => 'email_recip' . $queued . '@domain.com', 'subject' => 'Reset your password!', 'body' => 'Your can reset your password in 5 minutes. Url: http://xxx/reset');
    echo 'submitting new job...
';
    var_dump($newJob);
    $kue->create('email', $newJob)->save();
    $queued++;
    sleep(1);
}