Example #1
0
 /**
  * Schedules task
  *
  * @param string        $name       Package name
  * @param array         $payload    Payload for task
  * @param int|DateTime  $start_at   Time of first run in unix timestamp format or as DateTime instance. Example: time()+2*60
  * @param int           $run_every  Time in seconds between runs. If omitted, task will only run once.
  * @param int|DateTime  $end_at     Time tasks will stop being enqueued in unix timestamp or as DateTime instance format.
  * @param int           $run_times  Number of times to run task.
  * @param int           $priority   Priority queue to run the job in (0, 1, 2). p0 is default.
  * @return string Created Schedule id
  * @throws CException
  */
 public function workerPostScheduleAdvanced($name, $payload = array(), $start_at, $run_every = null, $end_at = null, $run_times = null, $priority = null)
 {
     try {
         return $this->_worker->postScheduleAdvanced($name, $payload, $start_at, $run_every, $end_at, $run_times, $priority);
     } catch (Exception $e) {
         Yii::log('Error in IronWorker: ' . $e->getMessage(), 'error', 'ext.yiiron');
         throw new CException($e->getMessage());
     }
 }
<?php

require_once "phar://../iron_worker.phar";
$worker = new IronWorker();
$worker->debug_enabled = true;
$payload = array('key_one' => 'Payload', 'key_two' => 2);
# 3 minutes later
$start_at = time() + 3 * 60;
# Run task every 2 minutes 10 times
$schedule_id = $worker->postScheduleAdvanced("Scheduling", $payload, $start_at, 2 * 60, null, 10);
# Get schedule information
$schedule = $worker->getSchedule($schedule_id);
print_r($schedule);