Create a new job and save it to the specified queue.
public static enqueue ( string $queue, string $class, array $args = null, boolean $trackStatus = false ) : string | boolean | ||
$queue | string | The name of the queue to place the job in. |
$class | string | The name of the class that contains the code to execute the job. |
$args | array | Any optional arguments that should be passed when the job is executed. |
$trackStatus | boolean | 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 |
/** * 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)); } }
/** * @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")); } } }
/** * @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); }
/** * @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)); }
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()); }
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(); }
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))); }
/** * 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 }
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'); }
/** * 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); }
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; }
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'])); } }
/** * 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; }
public function enqueue(Job $job, $trackStatus = false) { if ($job instanceof ContainerAwareJob) { $job->setKernelOptions($this->kernelOptions); } $result = \Resque::enqueue($job->queue, \get_class($job), $job->args, $trackStatus); if ($trackStatus) { return new \Resque_Job_Status($result); } return null; }
public function actionQueue() { $class = Yii::$app->getRequest()->get('class'); if (empty($class)) { exit('Empty Job Class !!!'); } \Resque::setBackend('127.0.0.1:6379'); $args = array('time' => time(), 'array' => array('test' => 'test')); $jobId = \Resque::enqueue('mail', '\\i\\models\\jobs\\' . $class, $args, true); $this->redirect(Url::toRoute(['queue/queues'], true)); }
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(); }
/** * @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); }
public static function requeue($id) { // item = all(id) // item['retried_at'] = Time.now.rfc2822 // Resque.redis.lset(:failed, id, Resque.encode(item)) // Job.create(item['queue'], item['payload']['class'], *item['payload']['args']) $item = current(self::all($id, 1)); $item->retried_at = strftime('%a %b %d %H:%M:%S %Z %Y'); $data = json_encode($item); \Resque::redis()->lset('failed', $id, $data); \Resque::enqueue($item->queue, $item->payload->class, (array) $item->payload->args[0]); }
/** * Check if the job can acquire the processing lock. * * This will requeue the given job upon failure, if the requeue parameter is * set to true. * * @param Resque_Job $job * The resque job. * * @return bool * If the job was acquired. * * @throws Resque_Job_DontPerform */ public static function beforePerform(Resque_Job $job) { if (Php_Resque::redis()->setnx($job->payload['args'][0]['drupal_unique_key'], '1')) { return TRUE; } else { if ($job->payload['args'][0]['requeue']) { Php_Resque::enqueue($job->queue, $job->payload['class'], $job->payload['args'][0], TRUE); throw new Resque_Job_DontPerform(); } else { throw new Resque_Job_DontPerform(); } } }
/** * Executes the cronjob task * * @param mixed $pid * @param mixed $md5 * @internal param RenaApp $app */ public static function execute($pid, $md5) { /** @var RenaApp $app */ $app = RenaApp::getInstance(); $toUpgrade = $app->Db->query("SELECT killID FROM killmails WHERE upgraded = 0 AND processed != 1 ORDER BY dateAdded ASC LIMIT 100", array(), 1); if ($toUpgrade) { foreach ($toUpgrade as $kill) { \Resque::enqueue("turbo", "\\ProjectRena\\Task\\Resque\\upgradeKillmail", array("killID" => $kill["killID"])); } } exit; // Keep this at the bottom, to make sure the fork exits }
/** * Performs the task, can access all $this->crap setup in setUp) */ public function perform() { $url = $this->args["url"]; $warID = $this->args["warID"]; $data = json_decode($this->app->cURL->getData($url, 0), true); $killmailData = $this->app->CrestFunctions->generateFromCREST(array("killID" => $data["killID"], "killmail" => $data)); $hash = $this->app->CrestFunctions->generateCRESTHash($killmailData); $json = json_encode($killmailData, JSON_NUMERIC_CHECK); $insert = $this->app->killmails->insertIntoKillmails($data["killID"], 0, $hash, "warID:{$warID}", $json); // Upgrade it if ($insert > 0) { \Resque::enqueue("turbo", "\\ProjectRena\\Task\\Resque\\upgradeKillmail", array("killID" => $data["killID"])); } }
/** * Performs the task, can access all $this->crap setup in setUp) */ public function perform() { if ($this->app->Storage->get("Api904") >= date("Y-m-d H:i:s")) { return; } $this->app->StatsD->increment("ccpRequests"); $fetchData = unserialize($this->args["fetchData"]); $keyID = $fetchData["keyID"]; $vCode = $this->app->ApiKeys->getVCodeByKeyID($keyID); $characterID = $fetchData["characterID"]; $maxKillID = $fetchData["maxKillID"]; $isDirector = $fetchData["isDirector"]; if ($isDirector) { $data = $this->getData($keyID, $vCode); } else { $data = $this->getData($keyID, $vCode, $characterID); } $cachedUntil = $data["cachedUntil"]; $maxKillID = 0; $kills = $data["result"]["kills"]; if (!empty($kills)) { foreach ($kills as $kill) { // Remove that bloody string value thing unset($kill["_stringValue"]); // Set the killID $killID = (int) $kill["killID"]; $kill["killID"] = (int) $kill["killID"]; // Generate the hash $hash = $this->app->CrestFunctions->generateCRESTHash($kill); // Create the source $source = "apiKey:" . $keyID; // json encode the killData $json = json_encode($kill, JSON_NUMERIC_CHECK); // insert the killData to the killmails table $inserted = $this->app->killmails->insertIntoKillmails($killID, 0, $hash, $source, $json); // Update the maxKillID $maxKillID = max($maxKillID, $killID); // Push it to the queue if it inserted, also poke statsd to increment the tracker for it // Move all of this to killmail parser, then add more data to the array, THEN push it out if ($inserted > 0) { $this->app->StatsD->increment("killmailsAdded"); // Process the killID \Resque::enqueue("turbo", "\\ProjectRena\\Task\\Resque\\upgradeKillmail", array("killID" => $killID)); } } } $this->app->ApiKeyCharacters->setMaxKillID($keyID, $characterID, $maxKillID); $this->app->ApiKeyCharacters->setCachedUntil($keyID, $characterID, $cachedUntil); $this->app->ApiKeyCharacters->setLastChecked($keyID, $characterID, date("Y-m-d H:i:s")); }
/** * @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; } $toFetch = $app->Db->query("SELECT * FROM apiKeyCharacters WHERE cachedUntil < now() OR lastChecked < date_sub(now(), INTERVAL 24 HOUR) ORDER BY lastChecked LIMIT 500", array(), 1); if ($toFetch) { foreach ($toFetch as $apiFetches) { \Resque::enqueue("important", "\\ProjectRena\\Task\\Resque\\killMailFetcher", array("fetchData" => serialize($apiFetches))); } } exit; // Keep this at the bottom, to make sure the fork exits }
public static function add($job_name, $queue_name, $args = array()) { \Resque::setBackend('127.0.0.1:6379'); if (strpos($queue_name, ':') !== false) { list($namespace, $queue_name) = explode(':', $queue_name); \Resque_Redis::prefix($namespace); } try { $klass = new \ReflectionClass($job_name); $jobId = \Resque::enqueue($queue_name, $klass->getName(), $args, true); return $jobId; } catch (\ReflectionException $rfe) { throw new \RuntimeException($rfe->getMessage()); } }
public function testRecreatedJobWithTrackingStillTracksStatus() { $originalToken = Resque::enqueue('jobs', 'Test_Job', null, true); $job = $this->worker->reserve(); // Mark this job as being worked on to ensure that the new status is still // waiting. $this->worker->workingOn($job); // Now recreate it $newToken = $job->recreate(); // Make sure we've got a new job returned $this->assertNotEquals($originalToken, $newToken); // Now check the status of the new job $newJob = Resque_Job::reserve('jobs'); $this->assertEquals(Resque_Job_Status::STATUS_WAITING, $newJob->getStatus()); }
/** * Manually enqueue a job via CLI. * * @param $job_class * Camelized job class name * @param $args ... * (optional) one or more arguments to pass to job. */ public function enqueue() { if (count($this->args) < 1) { $this->out('Which job class would you like to enqueue?'); return false; } $job_class =& $this->args[0]; App::import('Component', 'Resque.Resque'); $params = array_diff_key($this->params, array_flip(array('working', 'app', 'root', 'webroot'))); $paramstr = ''; foreach ($params as $key => &$value) { $paramstr .= ($paramstr ? ', ' : '') . $key . ':' . $value; } Resque::enqueue($job_queue = 'default', $job_class, $params); $this->out('Enqueued new job "' . $job_class . '"' . ($paramstr ? ' with params (' . $paramstr . ')' : '') . '...'); }
/** * @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; } $characters = $app->Db->query("SELECT characterID FROM characters WHERE lastUpdated < date_sub(now(), INTERVAL 7 DAY) AND characterID != 0 ORDER BY lastUpdated LIMIT 500", array(), 0); if ($characters) { foreach ($characters as $character) { // Get the characterID to update $characterID = $character["characterID"]; // Throw the ID after Resque which will update the characters information \Resque::enqueue("default", "\\ProjectRena\\Task\\Resque\\updateCharacter", array("characterID" => $characterID)); } } exit; }
/** * @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; } $apiKeys = $app->Db->query("SELECT keyID, vCode FROM apiKeys WHERE lastValidation < date_sub(now(), INTERVAL 6 HOUR) ORDER BY lastValidation DESC LIMIT 500", array(), 0); if ($apiKeys) { foreach ($apiKeys as $api) { $keyID = $api["keyID"]; $vCode = $api["vCode"]; // Update the lastValidation to in ten minutes, just so we don't insert it again and again \Resque::enqueue("now", "\\ProjectRena\\Task\\Resque\\updateApiKeys", array("keyID" => $keyID, "vCode" => $vCode)); } } exit; }
/** * Performs the task, can access all $this->crap setup in setUp) */ public function perform() { $url = $this->args["url"]; $warID = $this->args["warID"]; $data = json_decode($this->app->cURL->getData($url, 0), true); $pageCount = $data["pageCount"]; $currPage = 1; while ($currPage <= $pageCount) { $data = json_decode($this->app->cURL->getData($url . "?page=" . $currPage, 0), true); $killmails = $data["items"]; foreach ($killmails as $killmail) { $killmailURL = $killmail["href"]; $killID = $killmail["id"]; $this->app->Db->execute("INSERT INTO warKillmails (killID, warID) VALUES (:killID, :warID)", array(":killID" => $killID, ":warID" => $warID)); \Resque::enqueue("turbo", "\\ProjectRena\\Task\\Resque\\crestKillmailFetcher", array("url" => $killmailURL, "warID" => $warID)); } $currPage++; } }