저자: Chris Boulton (chris@bigcommerce.com)
예제 #1
0
 public function restGetQueueAdd()
 {
     $this->changeViewModel('json');
     $queue = $this->params()->fromQuery('queue', 'default');
     $jobId = \Resque::enqueue($queue, 'Core\\Jobs\\TestJob', array('name' => $queue), true);
     return new JsonModel(array('id' => $jobId, 'size' => \Resque::size($queue)));
 }
예제 #2
0
파일: Resque.php 프로젝트: klimis/php-edge
 /**
  * Return an instance of the Resque_Redis class instantiated for Resque.
  *
  * @return Resque_Redis Instance of Resque_Redis.
  */
 public static function redis()
 {
     // Detect when the PID of the current process has changed (from a fork, etc)
     // and force a reconnect to redis.
     $pid = getmypid();
     if (self::$pid !== $pid) {
         self::$redis = null;
         self::$pid = $pid;
     }
     if (!is_null(self::$redis)) {
         return self::$redis;
     }
     $server = self::$redisServer;
     if (empty($server)) {
         $server = 'localhost:6379';
     }
     if (is_array($server)) {
         require_once dirname(__FILE__) . '/Resque/RedisCluster.php';
         self::$redis = new Resque_RedisCluster($server);
     } else {
         if (strpos($server, 'unix:') === false) {
             list($host, $port) = explode(':', $server);
         } else {
             $host = $server;
             $port = null;
         }
         require_once dirname(__FILE__) . '/Resque/Redis.php';
         $redisInstance = new Resque_Redis($host, $port);
         $redisInstance->prefix(self::$namespace);
         self::$redis = $redisInstance;
     }
     self::$redis->select(self::$redisDatabase);
     return self::$redis;
 }
예제 #3
0
 /**
  * Executes the cronjob task
  *
  * @param mixed $pid
  * @param mixed $md5
  */
 public static function execute($pid, $md5)
 {
     /** @var RenaApp $app */
     $app = RenaApp::getInstance();
     // Foreach page, throw the war url in question at the Resque task
     $data = json_decode($app->cURL->getData("https://public-crest.eveonline.com/wars/", 0), true);
     $pageCount = $data["pageCount"];
     $currPage = 1;
     while ($currPage <= $pageCount) {
         // Get the data for the current page
         $data = json_decode($app->cURL->getData("https://public-crest.eveonline.com/wars/?page=" . $currPage, 0), true);
         foreach ($data["items"] as $war) {
             // Figure out if it's already inserted, and if it has ended (or has zero kills)
             $inserted = $app->wars->getWarByID($war["id"]);
             // If nothing is inserted we'll update
             if (empty($inserted)) {
                 \Resque::enqueue("default", "\\ProjectRena\\Task\\Resque\\populateWars", array("url" => $war["href"]));
             }
             $date = new DateTime("+36 hour");
             $dateIn36Hours = $date->format("Y-m-d H:i:s");
             if (!empty($inserted) && $inserted["lastUpdated"] > $dateIn36Hours) {
                 \Resque::enqueue("default", "\\ProjectRena\\Task\\Resque\\populateWars", array("url" => $war["href"]));
             }
         }
         // Increment the currentPage variable, so we can fetch the next set of wars
         $currPage++;
     }
     exit;
     // Keep this at the bottom, to make sure the fork exits
 }
 /**
  * @param RemoteMessage $message
  * @return void
  */
 public function dispatch(RemoteMessage $message)
 {
     $this->events()->trigger(__FUNCTION__ . '.pre', $this, array('message' => $message));
     $payload = array('message_class' => get_class($message), 'message_data' => $message->toArray());
     $jobId = \Resque::enqueue($this->queue, $this->receiverJobClass, $payload, $this->trackStatus);
     $this->events()->trigger(__FUNCTION__ . '.post', $this, array('message' => $message, 'jobId' => $jobId));
 }
예제 #5
0
 /**
  * Check that all needed and option params have been set
  *
  *
  */
 public function init()
 {
     // Ensure the composer autoloader is loaded so dependencies are loaded correctly
     require_once BASE_PATH . '/vendor/autoload.php';
     parent::init();
     $numWorkers = $this->request->getVar('count');
     if ($numWorkers > 1 && !function_exists('pcntl_fork')) {
         throw new Exception('This module need the pcntl PHP module');
     } else {
         if ($numWorkers) {
             $this->numWorkers = $numWorkers;
         }
     }
     if (php_sapi_name() !== 'cli') {
         echo 'The resque runner must be started in a CLI environment.';
         exit(1);
     }
     if (!$this->request->getVar('queue')) {
         echo "Set 'queue' parameter to containing the list of queues to work on.\n";
         exit(1);
     }
     $this->queue = $this->request->getVar('queue');
     if ($this->request->getVar('backend')) {
         Resque::setBackend($this->request->getVar('backend'));
     }
     $this->logger = new SSResqueLogger((bool) $this->request->getVar('verbose'));
 }
 public function perform()
 {
     \Resque::setBackend('127.0.0.1:6379');
     \Resque::enqueue('default', 'ProofPilot\\Jobs\\VerificationNoticeJob', array());
     \Resque::enqueue('default', 'ProofPilot\\Jobs\\InterventionStartJob', array());
     \Resque::enqueue('default', 'ProofPilot\\Jobs\\GeneralNotificationInterventionJob', array());
 }
예제 #7
0
파일: Resque.php 프로젝트: hungnv0789/vhtm
	public static function setBackend($server)
	{
		list($host, $port) = explode(':', $server);

		require_once dirname(__FILE__).'/Resque/Redis.php';
		self::$redis = new Resque_Redis($host, $port);
	}
예제 #8
0
 /**
  * Performs the task, can access all $this->crap setup in setUp)
  */
 public function perform()
 {
     $url = $this->args["url"];
     $data = json_decode($this->app->cURL->getData($url, 0), true);
     $warID = $data["id"];
     $timeDeclared = $data["timeDeclared"];
     $timeStarted = $data["timeStarted"];
     $timeFinished = $data["timeFinished"];
     $openForAllies = $data["openForAllies"];
     $mutual = $data["mutual"];
     $aggressor = $data["aggressor"]["id"];
     $aggressorShipsKilled = $data["aggressor"]["shipsKilled"];
     $aggressorISKKilled = $data["aggressor"]["iskKilled"];
     $defender = $data["defender"]["id"];
     $defenderShipsKilled = $data["defender"]["shipsKilled"];
     $defenderISKKilled = $data["defender"]["iskKilled"];
     $lastUpdated = date("Y-m-d H:i:s");
     $this->app->wars->insertWar($warID, $timeDeclared, $timeStarted, $timeFinished, $openForAllies, $mutual, $aggressor, $aggressorShipsKilled, $aggressorISKKilled, $defender, $defenderShipsKilled, $defenderISKKilled);
     $this->app->Db->execute("UPDATE wars SET lastUpdated = :lastUpdated WHERE warID = :warID", array(":lastUpdated" => $lastUpdated, ":warID" => $warID));
     // Throw the killmail url after the killmail populate task
     if ($aggressorShipsKilled > 0 || $defenderShipsKilled > 0) {
         $killmailURL = $data["killmails"];
         \Resque::enqueue("default", "\\ProjectRena\\Task\\Resque\\populateWarKillmails", array("url" => $killmailURL, "warID" => $warID));
     }
 }
 public function control()
 {
     $this->redirectToSternIndiaEndpoint('forgot.php');
     $config = Config::getInstance();
     //$this->addToView('is_registration_open', $config->getValue('is_registration_open'));
     // if (isset($_POST['email']) && $_POST['Submit'] == 'Send Reset') {
     // /$_POST['email'] = '*****@*****.**';
     if (isset($_POST['email'])) {
         $this->disableCaching();
         $dao = DAOFactory::getDAO('UserDAO');
         $user = $dao->getByEmail($_POST['email']);
         if (isset($user)) {
             $token = $user->setPasswordRecoveryToken();
             $es = new ViewManager();
             $es->caching = false;
             //$es->assign('apptitle', $config->getValue('app_title_prefix')."ThinkUp" );
             $es->assign('first_name', $user->first_name);
             $es->assign('recovery_url', "session/reset.php?token={$token}");
             $es->assign('application_url', Utils::getApplicationURL(false));
             $es->assign('site_root_path', $config->getValue('site_root_path'));
             $message = $es->fetch('_email.forgotpassword.tpl');
             $subject = $config->getValue('app_title_prefix') . "Stern India Password Recovery";
             //Will put the things in queue to mail the things.
             Resque::enqueue('user_mail', 'Mailer', array($_POST['email'], $subject, $message));
             $this->addToView('link_sent', true);
         } else {
             $this->addErrorMessage('Error: account does not exist.');
         }
     }
     $this->setViewTemplate('Session/forgot.tpl');
     return $this->generateView();
 }
예제 #10
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //Init rena
     /** @var RenaApp $app */
     $app = RenaApp::getInstance();
     $run = true;
     $oldKillID = 0;
     do {
         $p = \RedisQ\Action::listen("redisq.zkillboard.com");
         if ($p["killID"] > $oldKillID) {
             // Get the killmail data.
             $k = $app->CrestFunctions->generateFromCREST($p);
             // Poke statsd
             $app->StatsD->increment("zKillboardReceived");
             // Now lets make the json and hash
             $json = json_encode($k, JSON_NUMERIC_CHECK);
             $hash = $app->CrestFunctions->generateCRESTHash($k);
             //$hash = hash("sha256", ":" . $k["killTime"] . ":" . $k["solarSystemID"] . ":" . $k["moonID"] . "::" . $k["victim"]["characterID"] . ":" . $k["victim"]["shipTypeID"] . ":" . $k["victim"]["damageTaken"] . ":");
             // Lets insert the killmail!
             $insert = $app->killmails->insertIntoKillmails($p["killID"], 0, $hash, "zkillboardRedisQ", $json);
             // Upgrade it
             if ($insert > 0) {
                 \Resque::enqueue("turbo", "\\ProjectRena\\Task\\Resque\\upgradeKillmail", array("killID" => $p["killID"]));
             }
         }
         $oldKillID = $p["killID"];
     } while ($run == true);
 }
예제 #11
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //Init rena
     /** @var RenaApp $app */
     $app = RenaApp::getInstance();
     $app->StatsD->increment("ccpRequests");
     $data = $app->EVEEVEAllianceList->getData();
     if (isset($data["result"]["alliances"])) {
         foreach ($data["result"]["alliances"] as $alliance) {
             $output->writeln("Updating/Adding: " . $alliance["name"]);
             // Update all the corporations in the alliance.. maybe we missed one?
             foreach ($alliance["memberCorporations"] as $corporation) {
                 \Resque::enqueue("default", "\\ProjectRena\\Task\\Resque\\updateCorporation", array("corporationID" => $corporation["corporationID"]));
             }
             $allianceID = $alliance["allianceID"];
             $allianceName = $alliance["name"];
             $allianceTicker = $alliance["shortName"];
             $memberCount = $alliance["memberCount"];
             $executorCorporationID = $alliance["executorCorpID"];
             $information = json_decode($app->cURL->getData("https://public-crest.eveonline.com/alliances/{$allianceID}/"), true)["description"];
             $app->alliances->updateAllianceDetails($allianceID, $allianceName, $allianceTicker, $memberCount, $executorCorporationID, $information);
             $app->alliances->setLastUpdated($allianceID, date("Y-m-d H:i:s"));
         }
     }
 }
예제 #12
0
 public function sendResetPasswordEmail($args)
 {
     require NOVOPHP_VENDORS_DIR . '/PHPResque/lib/Resque.php';
     date_default_timezone_set('GMT');
     Resque::setBackend(RESQUE_SERVER_REDIS);
     $jobId = Resque::enqueue("email", "ResetPasswordEmail_Job", $args, true);
     return $jobId;
 }
예제 #13
0
 private function getRedis()
 {
     $redis = \Resque::$redis;
     if ($redis === null) {
         $redis = \Resque::redis();
     }
     return $redis;
 }
예제 #14
0
파일: Job.php 프로젝트: buptning/php-resque
 /**
  * Find the next available job from the specified queues using blocking list pop
  * and return an instance of Resque_Job for it.
  *
  * @param array             $queues
  * @param int               $timeout
  * @return null|object Null when there aren't any waiting jobs, instance of Resque_Job when a job was found.
  */
 public static function reserveBlocking(array $queues, $timeout = null)
 {
     $item = Resque::blpop($queues, $timeout);
     if (!is_array($item)) {
         return false;
     }
     return new Resque_Job($item['queue'], $item['payload']);
 }
예제 #15
0
 /**
  * Enqueue the message.
  *
  * @param \PhpGcmQueue\Message $message Message to send.
  * @param \DateTime|boolean $delay When to send the message.
  */
 public static function send(Message $message, $delay = false)
 {
     $args = ['serverApiKey' => self::$serverApiKey, 'gcmUrl' => self::$gcmUrl, 'message' => $message->toArray(), 'queueName' => self::$queueName, 'sendJob' => self::$sendJob];
     if ($delay) {
         $args['delay'] = $delay->format('U');
     }
     \Resque::enqueue(self::$queueName, self::$sendJob, $args);
 }
예제 #16
0
 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');
 }
예제 #17
0
파일: Job.php 프로젝트: Rming/novophp
 /**
  * Find the next available job from the specified queue and return an
  * instance of Resque_Job for it.
  *
  * @param string $queue The name of the queue to check for a job in.
  * @return null|object Null when there aren't any waiting jobs, instance of Resque_Job when a job was found.
  */
 public static function reserve($queue)
 {
     $payload = Resque::pop($queue);
     if (!$payload) {
         return false;
     }
     return new Resque_Job($queue, $payload);
 }
예제 #18
0
 /**
  * Find the next available job from the specified queue and return an
  * instance of Resque_Job for it.
  *
  * @param string $queue The name of the queue to check for a job in.
  * @return null|object Null when there aren't any waiting jobs, instance of Resque_Job when a job was found.
  */
 public static function reserve($queue, $sm = null)
 {
     $payload = \Resque::pop($queue);
     if (!is_array($payload)) {
         return false;
     }
     return new ResqueJob($queue, $payload, $sm);
 }
예제 #19
0
 /**
  * @return Job[]
  */
 public function jobs()
 {
     $result = \Resque::redis()->lrange('queue:' . $this->name, 0, -1);
     $jobs = [];
     foreach ($result as $job) {
         $jobs[] = (new \Resque_Job($this->name, \json_decode($job, true)))->getInstance();
     }
     return $jobs;
 }
예제 #20
0
 /**
  * @expectedException Resque_RedisException
  */
 public function testRedisExceptionsAreSurfaced()
 {
     $mockCredis = $this->getMockBuilder('Credis_Client')->setMethods(['connect', '__call'])->getMock();
     $mockCredis->expects($this->any())->method('__call')->will($this->throwException(new CredisException('failure')));
     Resque::setBackend(function ($database) use($mockCredis) {
         return new Resque_Redis('localhost:6379', $database, $mockCredis);
     });
     Resque::redis()->ping();
 }
 public function schedule_update()
 {
     $this->Maintainer->updateExistingMaintainer('sjosegonzalez');
     $maintainers = $this->Maintainer->find('all', array('contain' => false, 'order' => array('Maintainer.username ASC')));
     foreach ($maintainers as $maintainer) {
         $this->out(sprintf(__('[Maintainer] %s'), $maintainer['Maintainer']['username']));
         Resque::enqueue('default', 'UpdateMaintainerJob', array($maintainer['Maintainer']['username']));
     }
 }
예제 #22
0
 public function setUp()
 {
     $config = file_get_contents(REDIS_CONF);
     preg_match('#^\\s*port\\s+([0-9]+)#m', $config, $matches);
     $this->redis = new Credis_Client('localhost', $matches[1]);
     Resque::setBackend('redis://localhost:' . $matches[1]);
     // Flush redis
     $this->redis->flushAll();
 }
예제 #23
0
 /**
  * Notify about the notice.
  *
  * If there is a PHP Resque client given in the configuration, then use that to queue up a job to
  * send this out later. This should help speed up operations.
  *
  * @param Airbrake\Notice $notice
  */
 public function notify(Notice $notice)
 {
     if ($this->configuration->queue && class_exists('Resque')) {
         $data = array('notice' => serialize($notice), 'configuration' => serialize($this->configuration));
         \Resque::enqueue($this->configuration->queue, 'Airbrake\\Resque\\NotifyJob', $data);
         return;
     }
     return $this->connection->send($notice);
 }
 /**
  * @param $pid
  * @param $md5
  */
 public static function execute($pid, $md5)
 {
     $app = RenaApp::getInstance();
     if ($app->Storage->get("Api904") >= date("Y-m-d H:i:s")) {
         return;
     }
     \Resque::enqueue("now", "\\ProjectRena\\Task\\Resque\\updateAlliances");
     exit;
 }
 /**
  * @return ArrayList
  */
 protected function getQueues()
 {
     $queues = Resque::queues();
     $queueList = new ArrayList();
     foreach ($queues as $idx => $queue) {
         $queueList->push(new ResqueQueue(array('ID' => $idx + 1, 'Name' => $queue, 'Size' => Resque::size($queue))));
     }
     return $queueList;
 }
 /**
  * Find the next available job from the specified queue and return an
  * instance of Resque_Job for it.
  *
  * @param string $queue The name of the queue to check for a job in.
  * @return null|object Null when there aren't any waiting jobs, instance of Resque_Job when a job was found.
  */
 public static function reserve($queue)
 {
     // 出队,拿到最早的job数据
     $payload = Resque::pop($queue);
     if (!is_array($payload)) {
         return false;
     }
     // 创建一个新的job
     return new Resque_Job($queue, $payload);
 }
예제 #27
0
 public function getJobs($start = 0, $stop = -1)
 {
     $jobs = \Resque::redis()->lrange('queue:' . $this->name, $start, $stop);
     $result = array();
     foreach ($jobs as $job) {
         $job = new \Resque_Job($this->name, \json_decode($job, true));
         $result[] = $job->getInstance();
     }
     return $result;
 }
예제 #28
0
 public static function top_images()
 {
     require_library('TopImages');
     $log = HarvestProcessLog::create(array('process_name' => 'Top Images'));
     $top_images = new TopImages();
     $top_images->begin_process();
     $top_images->top_concept_images(true);
     $top_images->top_concept_images(false);
     \Resque::enqueue('harvesting', 'CodeBridge', array('cmd' => 'denormalize_tables'));
     $log->finished();
 }
예제 #29
0
 /**
  * @param $queriesFile
  * @param bool $groupByTable
  * @return int
  */
 public function enqueueQueriesFromFile($queriesFile, $groupByTable = false)
 {
     if ($groupByTable) {
         $queries = $this->getGroupedQueries(file_get_contents($queriesFile));
     } else {
         $queries = array(file_get_contents($queriesFile));
     }
     foreach ($queries as $query) {
         Resque::enqueue('upgrade', 'Job', ['q' => $query]);
     }
     return count($queries);
 }
예제 #30
0
파일: Resque.php 프로젝트: Rming/novophp
 /**
  * Given a host/port combination separated by a colon, set it as
  * the redis server that Resque will talk to.
  *
  * @param mixed $server Host/port combination separated by a colon, or
  * a nested array of servers with host/port pairs.
  */
 public static function setBackend($server, $database = 0)
 {
     if (is_array($server)) {
         require_once dirname(__FILE__) . '/Resque/RedisCluster.php';
         self::$redis = new Resque_RedisCluster($server);
     } else {
         list($host, $port) = explode(':', $server);
         require_once dirname(__FILE__) . '/Resque/Redis.php';
         self::$redis = new Resque_Redis($host, $port);
     }
     self::redis()->select($database);
 }