/** * Execute the given job with the given argument ID. * Mocks away the mailer, so mails can be retrieved through {@link #getMails()}. * Does not return anything. * * @see #getMails() * @see #getJobType() */ function executeJob($user, $arg_id) { // insert in the mock rates $rates = $this->getRates(); // by using _latest_ticker we get free mocking, we don't have to insert // things into the database, and we don't have to delete them later // since they are only local to this scope foreach ($rates as $ticker) { set_latest_ticker($ticker); } // now execute the job $q = db()->prepare("INSERT INTO jobs SET user_id=?, job_type=?, job_prefix=?, arg_id=?"); $q->execute(array($user['id'], $this->getJobType(), \Openclerk\Jobs\JobQueuer::getJobPrefix($this->getJobType()), $arg_id)); $job_id = db()->lastInsertId(); $q = db()->prepare("SELECT * FROM jobs WHERE id=?"); $q->execute(array($job_id)); $job = $q->fetch(); require_once __DIR__ . "/../batch/_batch_insert.php"; require __DIR__ . "/../jobs/" . $this->getJobType() . ".php"; // reset the mailer unset($__mock_mailer); }
/** * Get the latest ticker value for the given exchange and currency pairs. * Allows for caching these values. * @returns false if no ticker value could be found. */ function get_latest_ticker($exchange, $cur1, $cur2) { $key = $exchange . '_' . $cur1 . '_' . $cur2; global $_latest_tickers; if (!isset($_latest_tickers[$key])) { $latest_tickers[$key] = false; $q = db()->prepare("SELECT * FROM ticker_recent WHERE exchange=:exchange AND currency1=:currency1 AND currency2=:currency2 LIMIT 1"); $q->execute(array("exchange" => $exchange, "currency1" => $cur1, "currency2" => $cur2)); if ($ticker = $q->fetch()) { set_latest_ticker($ticker); } } return isset($_latest_tickers[$key]) ? $_latest_tickers[$key] : false; }