• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Resque_Event类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: enqueueAt

 /**
  * Enqueue a job for execution at a given timestamp.
  *
  * Identical to Resque::enqueue, however the first argument is a timestamp
  * (either UNIX timestamp in integer format or an instance of the DateTime
  * class in PHP).
  *
  * @param DateTime|int $at Instance of PHP DateTime object or int of UNIX timestamp.
  * @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.
  */
 public static function enqueueAt($at, $queue, $class, $args = array())
 {
     self::validateJob($class, $queue);
     $job = self::jobToHash($queue, $class, $args);
     self::delayedPush($at, $job);
     Resque_Event::trigger('afterRepeatSchedule', array('at' => $at, 'queue' => $queue, 'class' => $class, 'args' => $args));
 }
开发者ID:commonledger,项目名称:php-resque-repeater,代码行数:19,代码来源:ResqueRepeater.php


示例2: testAfterEnqueueEventCallbackFires

 public function testAfterEnqueueEventCallbackFires()
 {
     $callback = 'afterEnqueueEventCallback';
     $event = 'afterEnqueue';
     Resque_Event::listen($event, array($this, $callback));
     Resque::enqueue('jobs', 'Test_Job', array('somevar'));
     $this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
 }
开发者ID:hobodave,项目名称:php-resque,代码行数:8,代码来源:EventTest.php


示例3: fail

 /**
  * Mark the current job as having failed.
  *
  * @param $exception
  */
 public function fail($exception)
 {
     Resque_Event::trigger('onFailure', array('exception' => $exception, 'job' => $this));
     $this->updateStatus(Resque_Job_Status::STATUS_FAILED);
     Resque_Failure::create($this->payload, $exception, $this->worker, $this->queue);
     Resque_Stat::incr('failed');
     Resque_Stat::incr('failed:' . $this->worker);
 }
开发者ID:snikius,项目名称:php-resque,代码行数:13,代码来源:Job.php


示例4: enqueueDelayedItemsForTimestamp

 /**
  * Schedule all of the delayed jobs for a given timestamp.
  *
  * Searches for all items for a given timestamp, pulls them off the list of
  * delayed jobs and pushes them across to Resque.
  *
  * @param DateTime|int $timestamp Search for any items up to this timestamp to schedule.
  */
 public function enqueueDelayedItemsForTimestamp($timestamp)
 {
     $item = null;
     while ($item = ResqueRepeater::nextItemForTimestamp($timestamp)) {
         $this->log('queueing ' . $item['class'] . ' in ' . $item['queue'] . ' [delayed]');
         Resque_Event::trigger('beforeDelayedEnqueue', array('queue' => $item['queue'], 'class' => $item['class'], 'args' => $item['args']));
         $payload = array_merge(array($item['queue'], $item['class']), $item['args']);
         call_user_func_array('Resque::enqueue', $payload);
     }
 }
开发者ID:commonledger,项目名称:php-resque-repeater,代码行数:18,代码来源:Worker.php


示例5: register

 /**
  * Register php-resque-statsd in php-resque.
  *
  * Register all callbacks in php-resque for when a job is run. This is
  * automatically called at the bottom of this script if the appropriate
  * Resque classes are loaded.
  */
 public static function register()
 {
     // Core php-resque events
     Resque_Event::listen('afterEnqueue', 'ResqueStatsd::afterEnqueue');
     Resque_Event::listen('beforeFork', 'ResqueStatsd::beforeFork');
     Resque_Event::listen('afterPerform', 'ResqueStatsd::afterPerform');
     Resque_Event::listen('onFailure', 'ResqueStatsd::onFailure');
     // Add support for php-resque-scheduler
     Resque_Event::listen('afterSchedule', 'ResqueStatsd::afterSchedule');
 }
开发者ID:tomschlick,项目名称:php-resque-statsd,代码行数:17,代码来源:ResqueStatsD.php


示例6: enqueueDelayedItemsForTimestamp

 /**
  * Schedule all of the delayed jobs for a given timestamp.
  *
  * Searches for all items for a given timestamp, pulls them off the list of
  * delayed jobs and pushes them across to Resque.
  *
  * @param DateTime|int $timestamp Search for any items up to this timestamp to schedule.
  */
 public function enqueueDelayedItemsForTimestamp($timestamp)
 {
     $item = null;
     while ($item = ResqueScheduler::nextItemForTimestamp($timestamp)) {
         $this->log(array('message' => 'Moving scheduled job ' . strtoupper($item['class']) . ' to ' . strtoupper($item['queue']), 'data' => array('type' => 'movescheduled', 'args' => array('timestamp' => (int) $timestamp, 'class' => $item['class'], 'queue' => $item['queue'], 'job_id' => $item['args'][0]['id'], 'wait' => round(microtime(true) - (isset($item['s_time']) ? $item['s_time'] : 0), 3), 's_wait' => $timestamp - floor(isset($item['s_time']) ? $item['s_time'] : 0)))), self::LOG_TYPE_INFO);
         \Resque_Event::trigger('beforeDelayedEnqueue', array('queue' => $item['queue'], 'class' => $item['class'], 'args' => $item['args']));
         $payload = array_merge(array($item['queue'], $item['class']), $item['args'], array($item['track']));
         call_user_func_array('\\Resque::enqueue', $payload);
     }
 }
开发者ID:kamisama,项目名称:php-resque-ex-scheduler,代码行数:18,代码来源:Worker.php


示例7: testStopListeningRemovesListener

 public function testStopListeningRemovesListener()
 {
     $callback = 'beforePerformEventCallback';
     $event = 'beforePerform';
     Resque_Event::listen($event, array($this, $callback));
     Resque_Event::stopListening($event, array($this, $callback));
     $job = $this->getEventTestJob();
     $this->worker->perform($job);
     $this->worker->work(0);
     $this->assertNotContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was called though Resque_Event::stopListening was called');
 }
开发者ID:HMAZonderland,项目名称:php-resque-ex,代码行数:11,代码来源:EventTest.php


示例8: perform

 public function perform()
 {
     try {
         $closure = $this->getClosure();
         Resque_Event::trigger('beforePerform', $this);
         Resque_Job_Closure::invokeSerializableClosure($closure, $this, $this->getArguments());
         Resque_Event::trigger('afterPerform', $this);
     } catch (Resque_Job_DontPerform $e) {
         return false;
     }
     return true;
 }
开发者ID:snikius,项目名称:php-resque,代码行数:12,代码来源:Closure.php


示例9: enqueueAt

 /**
  * Enqueue a job for execution at a given timestamp.
  *
  * Identical to Resque::enqueue, however the first argument is a timestamp
  * (either UNIX timestamp in integer format or an instance of the DateTime
  * class in PHP).
  *
  * @param   DateTime|int $at            Instance of PHP DateTime object or int of UNIX timestamp.
  * @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      $trackStatus   Set to true to be able to monitor the status of a job.
  * @return  string                      Job ID
  */
 public static function enqueueAt($at, $queue, $class, $args = array(), $trackStatus = false)
 {
     self::validateJob($class, $queue);
     $args['id'] = md5(uniqid('', true));
     $args['s_time'] = time();
     $job = self::jobToHash($queue, $class, $args, $trackStatus);
     self::delayedPush($at, $job);
     if ($trackStatus) {
         \Resque_Job_Status::create($args['id'], Job\Status::STATUS_SCHEDULED);
     }
     \Resque_Event::trigger('afterSchedule', array('at' => $at, 'queue' => $queue, 'class' => $class, 'args' => $args));
     return $args['id'];
 }
开发者ID:kamisama,项目名称:php-resque-ex-scheduler,代码行数:27,代码来源:ResqueScheduler.php


示例10: __construct

 /**
  * Initialize the class and set its properties.
  *
  * @since    1.0.0
  * @param      string    $plugin_name       The name of this plugin.
  * @param      string    $version    The version of this plugin.
  */
 public function __construct($plugin_name, $version)
 {
     $this->plugin_name = $plugin_name;
     $this->version = $version;
     $this->redis = new Predis\Client(['scheme' => 'tcp', 'host' => REDIS_HOST, 'port' => REDIS_PORT, 'password' => REDIS_PASSWORD]);
     $this->blog_id = get_current_blog_id();
     if (function_exists('get_blog_details')) {
         $details = get_blog_details($this->blog_id, 'domain', false);
         $domain = $details->domain;
         $sub_domain = explode(".", $domain)[0];
         $this->sub_domain = $sub_domain;
     }
     Resque::setBackend(REDIS_HOST . ":" . REDIS_PORT, REDIS_DB);
     Resque_Event::listen('afterPerform', array('RooftopJob', 'afterPerform'));
 }
开发者ID:rooftopcms,项目名称:rooftop-queue-pusher,代码行数:22,代码来源:class-rooftop-queue-pusher-admin.php


示例11: perform

 public function perform()
 {
     try {
         Resque_Event::trigger('beforePerform', $this);
         $instance = $this->getInstance();
         if (method_exists($instance, 'setUp')) {
             $instance->setUp();
         }
         $method = $this->method;
         $instance->{$method}($this, $this->getArguments());
         if (method_exists($instance, 'tearDown')) {
             $instance->tearDown();
         }
         Resque_Event::trigger('afterPerform', $this);
     } catch (Resque_Job_DontPerform $e) {
         return false;
     }
     return true;
 }
开发者ID:snikius,项目名称:php-resque,代码行数:19,代码来源:Class.php


示例12: perform

 private function perform($job)
 {
     // $startTime = microtime(true);
     try {
         if (!$job instanceof \Randr\Job) {
             throw new \Exception('Job is not a class');
         }
         \Resque_Event::trigger('afterFork', $job);
         $rc = $job->perform();
         //$this->log(array('message' => 'done ID:' . $job->payload['id'], 'data' => array('type' => 'done', 'job_id' => $job->payload['id'], 'time' => round(microtime(true) - $startTime, 3) * 1000)), self::LOG_TYPE_INFO)
     } catch (Exception $e) {
         /*$this->log([
         			'message' => $job . ' failed: ' . $e->getMessage(),
         			'data' => [
         				'type' => 'fail',
         				'log' => $e->getMessage(),
         				'job_id' => $job->payload['id'],
         				'time' => round(microtime(true) - $startTime, 3) * 1000
         			]],
         			Resque_Worker::LOG_TYPE_ERROR
         		);
         		*/
         if ($job instanceof \Randr\Job) {
             $job->fail($e);
         }
         print "ERROR: " . $e->getMessage() . "\n";
     }
     $this->emit('finish', [$rc]);
     $job->updateStatus(\Resque_Job_Status::STATUS_COMPLETE);
     if ($this->ttl > 0) {
         $this->ttl--;
     }
     if ($this->ttl == 0) {
         print "TIME TO DIE for " . getmypid() . "\n";
         exit(0);
     }
 }
开发者ID:pwhelan,项目名称:randr,代码行数:37,代码来源:Unit.php


示例13: enqueue

 /**
  * 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 $trackStatus Set to true to be able to monitor the status of a job.
  *
  * @return string
  */
 public static function enqueue($queue, $class, $args = null, $trackStatus = false)
 {
     $result = Resque_Job::create($queue, $class, $args, $trackStatus);
     if ($result) {
         Resque_Event::trigger('afterEnqueue', array('class' => $class, 'args' => $args, 'queue' => $queue));
     }
     return $result;
 }
开发者ID:rolies106,项目名称:yii2resque,代码行数:18,代码来源:Resque.php


示例14: enqueueFromConfig

 protected function enqueueFromConfig($config)
 {
     if (isset($config['cron'])) {
         //ResqueScheduler::removeDelayed($config['args']['queue'], $config['class'], $config['args']);
         $this->logger->log(Psr\Log\LogLevel::NOTICE, 'queueing {class} in {queue} Scheduled {schedule_at}', array('class' => $config['class'], 'queue' => $config['args']['queue'], 'schedule_at' => $config['schedule_at']));
         ResqueScheduler::enqueueAt($config['schedule_at'], $config['args']['queue'], $config['class'], $config['args']);
     } else {
         $this->logger->log(Psr\Log\LogLevel::INFO, 'queueing {class} in {queue} [delayed]', array('class' => $config['class'], 'queue' => $config['queue']));
         Resque_Event::trigger('beforeDelayedEnqueue', array('queue' => $config['queue'], 'class' => $config['class'], 'args' => $config['args']));
         $payload = array_merge(array($config['queue'], $config['class']), $config['args']);
         call_user_func_array('Resque::enqueue', $payload);
     }
 }
开发者ID:neilmillard,项目名称:php-resque-scheduler,代码行数:13,代码来源:Worker.php


示例15: startup

 /**
  * Perform necessary actions to start a worker.
  */
 private function startup()
 {
     $this->registerSigHandlers();
     $this->pruneDeadWorkers();
     Resque_Event::trigger('beforeFirstFork', $this);
     $this->registerWorker();
 }
开发者ID:realestateconz,项目名称:php-resque,代码行数:10,代码来源:Worker.php


示例16: enqueue

 /**
  * 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 $trackStatus Set to true to be able to monitor the status of a job.
  *
  * @return string|boolean Job ID when the job was created, false if creation was cancelled due to beforeEnqueue
  */
 public static function enqueue($queue, $class, $args = null, $trackStatus = false)
 {
     $id = Resque::generateJobId();
     $hookParams = array('class' => $class, 'args' => $args, 'queue' => $queue, 'id' => $id);
     try {
         Resque_Event::trigger('beforeEnqueue', $hookParams);
     } catch (Resque_Job_DontCreate $e) {
         return false;
     }
     Resque_Job::create($queue, $class, $args, $trackStatus, $id);
     Resque_Event::trigger('afterEnqueue', $hookParams);
     return $id;
 }
开发者ID:varvar,项目名称:php-resque,代码行数:23,代码来源:Resque.php


示例17: enqueue

 /**
  * 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 $trackStatus Set to true to be able to monitor the status of a job.
  * @param string $method method name to invoke in job class.
  * @return string
  */
 public static function enqueue($queue, $call, $args = null, $trackStatus = false, $method = 'fire')
 {
     if ($call instanceof Closure) {
         $serialized = serialize(new SerializableClosure($call));
         $result = Resque_Job_Closure::create($queue, $serialized, $args, $trackStatus);
         if ($result) {
             Resque_Event::trigger('afterEnqueue', array('class' => $serialized, 'args' => $args, 'queue' => $queue, 'id' => $result));
         }
         return $result;
     }
     $result = Resque_Job_Class::create($queue, $call, $args, $trackStatus, $method);
     if ($result) {
         Resque_Event::trigger('afterEnqueue', array('class' => $call, 'args' => $args, 'queue' => $queue, 'id' => $result, 'method' => $method));
     }
     return $result;
 }
开发者ID:snikius,项目名称:php-resque,代码行数:26,代码来源:Resque.php


示例18: function

<?php

use CultuurNet\UDB3\Log\ContextEnrichingLogger;
require_once 'vendor/autoload.php';
Resque_Event::listen('beforePerform', function (Resque_Job $job) {
    /** @var \Silex\Application $app */
    $app = (require __DIR__ . '/bootstrap.php');
    $app->boot();
    $args = $job->getArguments();
    $context = unserialize(base64_decode($args['context']));
    $app['impersonator']->impersonate($context);
    $app['logger.fatal_job_error'] = new ContextEnrichingLogger($app['logger.command_bus'], array('job_id' => $job->payload['id']));
    $errorLoggingShutdownHandler = function () use($app) {
        $error = error_get_last();
        $fatalErrors = E_ERROR | E_RECOVERABLE_ERROR;
        $wasFatal = $fatalErrors & $error['type'];
        if ($wasFatal) {
            $app['logger.fatal_job_error']->error('job_failed');
            $app['logger.fatal_job_error']->debug('error caused job failure', ['error' => $error]);
        }
    };
    register_shutdown_function($errorLoggingShutdownHandler);
    // Command bus service name is based on queue name + _command_bus_out.
    // Eg. Queue "event" => command bus "event_command_bus_out".
    $commandBusServiceName = getenv('QUEUE') . '_command_bus_out';
    // Allows to access the command bus in perform() of jobs that
    // come out of the queue.
    \CultuurNet\UDB3\CommandHandling\QueueJob::setCommandBus($app[$commandBusServiceName]);
});
开发者ID:cultuurnet,项目名称:udb3-silex,代码行数:29,代码来源:worker_bootstrap.php


示例19: clearListeners

 public static function clearListeners()
 {
     \Resque_Event::clearListeners();
 }
开发者ID:hlegius,项目名称:PHPResqueBundle,代码行数:4,代码来源:Event.php


示例20: startup

 /**
  * Perform necessary actions to start a worker.
  */
 protected function startup()
 {
     $this->log(array('message' => 'Starting worker ' . $this, 'data' => array('type' => 'start', 'worker' => (string) $this)), self::LOG_TYPE_INFO);
     $this->registerSigHandlers();
     $this->pruneDeadWorkers();
     Resque_Event::trigger('beforeFirstFork', $this);
     $this->registerWorker();
 }
开发者ID:misterniall,项目名称:php-resque-ex,代码行数:11,代码来源:Worker.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Rest类代码示例发布时间:2022-05-23
下一篇:
PHP Resque类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap