// 设置日志 if (!isset($logger) || !is_object($logger)) { $logger = new Resque_Log(false); }
// 设置Redis命名空间前缀,默认:resque if (!empty($prefix)) { $logger->log(LogLevel::INFO, 'Prefix set to {prefix}', array('prefix' => $prefix)); Resque_Redis::prefix($prefix); }
// 启动 Worker if ($count > 1) { for ($i = 0; $i < $count; ++$i) { $pid = Resque::fork(); if ($pid === false || $pid === -1) { $logger->log(LogLevel::EMERGENCY, 'Could not fork worker {count}', array('count' => $i)); die(); } elseif (!$pid) { // Child, start the worker $queues = explode(',', $queue_name); $worker = new Resque_Worker($queues); $worker->setLogger($logger); $logger->log(LogLevel::NOTICE, 'Starting worker {worker}', array('worker' => $worker)); $worker->work($interval); break; } } } else { // Start a single worker $queues = explode(',', $queue_name); $worker = new Resque_Worker($queues); $worker->setLogger($logger);
/** * Create a new job and save it to the specified queue. * * @param string $queue The name of the queue to place the job in. * @param string $class The name of the class that contains the code to execute the job. * @param array $args Any optional arguments that should be passed when the job is executed. * * @return string */ publicfunctioncreateJob($queue, $class, $args = array(), $track_status = false) {
return Resque::enqueue($queue, $class, $args, $track_status); } /** * Create a new scheduled job and save it to the specified queue. * * @param int $in Second count down to job. * @param string $queue The name of the queue to place the job in. * @param string $class The name of the class that contains the code to execute the job. * @param array $args Any optional arguments that should be passed when the job is executed. */ publicfunctionenqueueJobIn($in, $queue, $class, $args = array()) { ResqueScheduler::enqueueIn($in, $queue, $class, $args); } /** * Create a new scheduled job and save it to the specified queue. * * @param timestamp $at UNIX timestamp when job should be executed. * @param string $queue The name of the queue to place the job in. * @param string $class The name of the class that contains the code to execute the job. * @param array $args Any optional arguments that should be passed when the job is executed. */ publicfunctionenqueueJobAt($at, $queue, $class, $args = array()) {