当前位置: 首页>>代码示例>>PHP>>正文


PHP Resque::push方法代码示例

本文整理汇总了PHP中Resque::push方法的典型用法代码示例。如果您正苦于以下问题:PHP Resque::push方法的具体用法?PHP Resque::push怎么用?PHP Resque::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Resque的用法示例。


在下文中一共展示了Resque::push方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * 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.
  * @param boolean $monitor Set to true to be able to monitor the status of a job.
  *
  * @return string
  */
 public static function create($queue, $class, $args = null, $monitor = false)
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     $new = true;
     if (isset($args['id'])) {
         $id = $args['id'];
         unset($args['id']);
         $new = false;
     } else {
         $id = md5(uniqid('', true));
     }
     if (empty($args)) {
         $args = [];
     }
     Resque::push($queue, array('class' => $class, 'args' => array($args), 'id' => $id));
     if ($monitor) {
         if ($new) {
             Resque_Job_Status::create($id);
         } else {
             $statusInstance = new Resque_Job_Status($id);
             $statusInstance->update($id, Resque_Job_Status::STATUS_WAITING);
         }
     }
     return $id;
 }
开发者ID:protecinnovations,项目名称:php-resque-ex,代码行数:37,代码来源:Job.php

示例2: create

	/**
	 * 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|callback $method The name of the class that contains the code to execute the job, or an array containing a class name and method name
	 * @param array $args Any optional arguments that should be passed when the job is executed.
	 * @param boolean $monitor Set to true to be able to monitor the status of a job.
	 * @param string $include Path to a file to include before attempting to execute the callback
	 */
	public static function create($queue, $method, array $args=array(), $monitor = false, $include = '')
	{
		if (is_array($method)) {
			$class = $method[0];
			$method = $method[1];
		} else {
			$class = '';
		}

		$id = md5(uniqid('', true));

		$payload = array(
			'class' => $class,
			'method' => $method,
			'args' => $args,
			'id' => $id,
			'include' => $include,
		);

		Resque::push($queue, $payload);

		if($monitor) {
			Resque_Job_Status::create($id);
		}

		return $id;
	}
开发者ID:hungnv0789,项目名称:vhtm,代码行数:36,代码来源:Job.php

示例3: create

 /**
  * 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.
  * @param boolean $monitor Set to true to be able to monitor the status of a job.
  */
 public static function create($queue, $class, $args = null, $monitor = false)
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     $id = md5(uniqid('', true));
     Resque::push($queue, array('class' => $class, 'args' => $args, 'id' => $id));
     if ($monitor) {
         Resque_Job_Status::create($id);
     }
     return $id;
 }
开发者ID:Rming,项目名称:novophp,代码行数:20,代码来源:Job.php

示例4: create

 /**
  * 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.
  * @param boolean $monitor Set to true to be able to monitor the status of a job.
  * @param string $id Unique identifier for tracking the job. Generated if not supplied.
  *
  * @return string
  */
 public static function create($queue, $class, $args = null, $monitor = false, $id = null)
 {
     if (is_null($id)) {
         $id = Resque::generateJobId();
     }
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     Resque::push($queue, array('class' => $class, 'args' => array($args), 'id' => $id, 'queue_time' => microtime(true)));
     if ($monitor) {
         Resque_Job_Status::create($id);
     }
     return $id;
 }
开发者ID:SoftwarePunt,项目名称:php-resque,代码行数:25,代码来源:Job.php

示例5: create

 public static function create($queue, $class, $args = null, $monitor = false)
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     $id = md5(uniqid('', true));
     $data = array('class' => $class, 'args' => array($args), 'id' => $id, 'closure' => true, 'queue_time' => microtime(true));
     Log::info('Push closure:' . json_encode($data));
     Resque::push($queue, $data);
     if ($monitor) {
         Resque_Job_Status::create($id);
     }
     return $id;
 }
开发者ID:snikius,项目名称:php-resque,代码行数:14,代码来源:Closure.php

示例6: create

 /**
  * 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.
  * @param boolean $monitor Set to true to be able to monitor the status of a job.
  *
  * @return string
  */
 public static function create($queue, $class, $args = null, $monitor = false)
 {
     if ($args !== null && !is_array($args)) {
         throw new InvalidArgumentException('Supplied $args must be an array.');
     }
     // uniqid — 生成一个唯一ID,一个带前缀、基于当前时间微秒数的唯一ID
     $id = md5(uniqid('', true));
     // 将相应的类名/参数和id入队
     Resque::push($queue, array('class' => $class, 'args' => array($args), 'id' => $id));
     if ($monitor) {
         // 创建job的状态,以便监控这个job
         Resque_Job_Status::create($id);
     }
     return $id;
 }
开发者ID:CraryPrimitiveMan,项目名称:php-resque-1.2-annotated,代码行数:25,代码来源:Job.php

示例7: executeEdit

 /**
  * @return string|void
  * @throws sfStopException
  */
 public function executeEdit()
 {
     /** @var \FileImportHistory file_import_history */
     $this->file_import_history = $this->getFileImportHistoryOrCreate();
     $this->labels = $this->getLabels();
     if ($this->getRequest()->getMethod() == sfRequest::POST) {
         $this->updateFileImportHistoryFromRequest();
         //need an id
         if ($this->file_import_history->getVocabularyId()) {
             $schemaId = $this->file_import_history->getVocabularyId();
             $type = 'vocabulary';
         } else {
             $schemaId = $this->file_import_history->getSchemaId();
             $type = 'schema';
         }
         $filePath = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . 'csv' . DIRECTORY_SEPARATOR . $this->file_import_history->getFileName();
         $import = new ImportVocab($type, $filePath, $schemaId);
         $prolog = $import->processProlog();
         if (!$prolog) {
             $message = "Something went seriously wrong and we couldn't process your file at all (wish we could be more helpful)";
             return $this->handleImportError($message, $filePath);
         }
         $type_id = 'vocabulary' === $type ? 'vocabulary_id' : 'schema_id';
         //check to make sure that if there's a schema_id in the prolog that it matches the current ID
         if (isset($prolog['meta'][$type_id])) {
             if (is_array($prolog['meta'][$type_id])) {
                 $message = "You have a duplicate of one of the prolog columns ('reg_id', 'uri', 'type') in your data<br />We can't process the file until it's removed.";
                 return $this->handleImportError($message, $filePath);
             }
             if ($prolog['meta'][$type_id] != $schemaId) {
                 $message = "The " . $type . "_id in the file you are importing (" . $prolog['meta'][$type_id] . ") does not match the Element Set Id of this\n        Element Set (" . $schemaId . ")<br />You may be trying to import into the wrong Element Set?";
                 return $this->handleImportError($message, $filePath);
             }
         } else {
             $message = "Your file is missing a " . $type . "_id entry in the 'meta' section and we won't process it without one";
             return $this->handleImportError($message, $filePath);
         }
         //todo identify and warn of more processing errors with the prolog
         //check to make sure the user is an admin
         /** @var myUser $user */
         $user = $this->getUser();
         if (!$user->hasCredential(array(0 => array(0 => 'administrator', 1 => 'schemaadmin', 2 => 'vocabularyadmin')))) {
             $message = 'You must be an administrator of this Element Set to import.';
             return $this->handleImportError($message, $filePath);
         }
         $this->file_import_history->setResults("Queued for processing.");
         $this->saveFileImportHistory($this->file_import_history);
         $this->setFlash('notice', 'Your file has been accepted and queued for processing. Check back in a few minutes for the results');
         unset($import);
         $environment = SF_ENVIRONMENT;
         $importId = $this->file_import_history->getId();
         //todo it's at this point that we push this onto a queue for processing
         $job = Resque::push('ImportVocab\\ImportJob', array($schemaId, $filePath, $importId, $environment, $type));
         $job2 = Resque::push('ImportVocab\\UpdateRelatedJob', array($environment, $importId));
         return $this->redirect('import/show?id=' . $importId);
     }
 }
开发者ID:jonphipps,项目名称:Metadata-Registry,代码行数:61,代码来源:actions.class.php

示例8: runJob

 public function runJob($job, array $data = null, $queue = null)
 {
     return \Resque::push($job, $data, $queue);
 }
开发者ID:thrieu,项目名称:yii2-resque,代码行数:4,代码来源:Yii2Resque.php

示例9: perform

<?php

use Resque\Event;
use Resque\Logger;
// Test job class
class TestJob
{
    public function perform($args)
    {
        // Don't do anything
    }
}
// Lets record the forking time
Event::listen(array(Event::WORKER_FORK, Event::WORKER_FORK_CHILD), function ($event, $job) use($logger) {
    static $start = 0;
    if ($event === Event::WORKER_FORK_CHILD) {
        $exec = microtime(true) - $start;
        $logger->log('Forking process took ' . round($exec * 1000, 2) . 'ms', Logger::DEBUG);
    } else {
        $start = microtime(true);
    }
});
// When the job is about to be run, queue another one
Event::listen(Event::JOB_PERFORM, function ($event, $job) use($logger) {
    Resque::push('TestJob');
});
// Add a few jobs to the default queue
for ($i = 0; $i < 10; $i++) {
    Resque::push('TestJob');
}
开发者ID:mjphaynes,项目名称:php-resque,代码行数:30,代码来源:autoload.php

示例10: array

            break;
        case 'failnoclass':
            $job = Resque::push('\\Does\\Not\\Exist', array());
            break;
        case 'faillong':
            $job = Resque::push('FailLong', array());
            break;
        case 'failexception':
            $job = Resque::push('FailException', array());
            break;
        case 'failerror':
            $job = Resque::push('FailError', array());
            break;
        case 'closure':
            $job = Resque::push(function ($job) {
                echo 'This is an inline job! #' . $job->getId() . PHP_EOL;
            });
            break;
        case 'closure-delayed':
            $job = Resque::later(mt_rand(0, 30), function ($job) {
                echo 'This is a delayed inline job! #' . $job->getId() . PHP_EOL;
            });
            break;
    }
}
if ($job) {
    header('Location: ?id=' . $job->getId());
    exit;
}
echo '<pre><h1><a href="?">php-resque</a></h1><ul>' . '<li><a href="?action=reset">Reset</a></li>' . '<li><a href="?action=push">Push new job</a></li>' . '<li><a href="?action=delayed">Delayed job</a></li>' . '<li><a href="?action=delayedat">Delayed job in 2 mins</a></li>' . '<li><a href="?action=longrunning">Long running job</a></li>' . '<li><a href="?action=faillong">Fail due to running too long</a></li>' . '<li><a href="?action=failnoclass">Fail due to no class being found</a></li>' . '<li><a href="?action=failexception">Fail due to exception</a></li>' . '<li><a href="?action=failerror">Fail due to fatal error</a></li>' . '<li><a href="?action=closure">Push closure</a></li>' . '<li><a href="?action=closure-delayed">Delayed closure</a></li>' . '</ul>';
$rep = 150;
开发者ID:mjphaynes,项目名称:php-resque,代码行数:31,代码来源:index.php


注:本文中的Resque::push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。