create() public static method

Create a new job and save it to the specified queue.
public static create ( string $queue, string $class, array $data = null, integer $run_at ) : string
$queue string The name of the queue to place the job in
$class string The name of the class that contains the code to execute the job
$data array Any optional arguments that should be passed when the job is executed
$run_at integer Unix timestamp of when to run the job to delay execution
return string
Ejemplo n.º 1
0
 /**
  * Queue a job for later retrieval. Jobs are unique per queue and 
  * are deleted upon retrieval. If a given job (payload) already exists, 
  * it is updated with the new delay.
  *
  * @param  int    $delay This can be number of seconds or unix timestamp
  * @param  string $job   The job class
  * @param  mixed  $data  The job data
  * @param  string $queue The queue to add the job to
  * @return Job job instance
  */
 public function later($delay, $job, array $data = array(), $queue = null)
 {
     // If it's a datetime object conver to unix time
     if ($delay instanceof \DateTime) {
         $delay = $delay->getTimestamp();
     }
     if (!is_numeric($delay)) {
         throw new \InvalidArgumentException('The delay "' . $delay . '" must be an integer or DateTime object.');
     }
     // If the delay is smaller than 3 years then assume that an interval
     // has been passed i.e. 600 seconds, otherwise it's a unix timestamp
     if ($delay < 94608000) {
         $delay += time();
     }
     return Job::create($this->getQueue($queue), $job, $data, $delay);
 }