Exemplo n.º 1
0
 function testJobPrefix()
 {
     $this->assertEquals("ticker", JobQueuer::getJobPrefix("ticker_foo"));
     $this->assertEquals("ticker", JobQueuer::getJobPrefix("ticker_foo_bar"));
     $this->assertEquals("ticker", JobQueuer::getJobPrefix("ticker_"));
     $this->assertEquals("ticker", JobQueuer::getJobPrefix("ticker"));
     $this->assertEquals("ticker", JobQueuer::getJobPrefix("ticker-foo"));
     $this->assertEquals("ticker", JobQueuer::getJobPrefix("ticker-foo_bar"));
     $this->assertEquals("ticker", JobQueuer::getJobPrefix("ticker_foo-bar"));
     $this->assertEquals("ticker", JobQueuer::getJobPrefix("ticker-"));
     $this->assertEquals("ticker", JobQueuer::getJobPrefix("ticker"));
     $this->assertEquals("", JobQueuer::getJobPrefix(""));
 }
Exemplo n.º 2
0
    set_temporary_messages($messages);
    redirect(url_for(require_post("callback")));
}
// process 'test'
if (require_post('test', false) && require_post('id', false)) {
    // do we already have a job queued up?
    $q = db()->prepare("SELECT * FROM jobs WHERE is_executed=0 AND user_id=? AND is_test_job=1 LIMIT 1");
    $q->execute(array(user_id()));
    if ($job = $q->fetch()) {
        $errors[] = t("Cannot create a :title test, because you already have a :type test pending.", array(':title' => htmlspecialchars($account_data['title']), ':type' => get_exchange_name($job['job_type'])));
    } else {
        if ($account_data['disabled']) {
            $errors[] = t("Cannot test that job; that account type is disabled.");
        } else {
            $q = db()->prepare("INSERT INTO jobs SET\n      job_type=:job_type,\n      job_prefix=:job_prefix,\n      user_id=:user_id,\n      arg_id=:arg_id,\n      priority=:priority,\n      is_test_job=1");
            $q->execute(array('job_type' => $account_data['job_type'], 'job_prefix' => \Openclerk\Jobs\JobQueuer::getJobPrefix($account_data['exchange']), 'user_id' => user_id(), 'arg_id' => require_post('id'), 'priority' => get_site_config('job_test_priority')));
            $messages[] = t("Queued up a new :title test; results should be available shortly.", array(':title' => htmlspecialchars($account_data['title'])));
            set_temporary_messages($messages);
            redirect(url_for(require_post("callback")));
        }
    }
}
// process 'enable'
if (require_post('enable', false) && require_post('id', false)) {
    if (!can_user_add($user, $account_data['exchange'])) {
        $errors[] = t("Cannot enable :title: too many existing accounts.", array(':title' => $account_data['title'])) . ($user['is_premium'] ? "" : " " . t("To add more accounts, upgrade to a :premium_account.", array(':premium_account' => link_to(url_for('premium'), t('premium account')))));
    } else {
        if ($account_data['disabled']) {
            $errors[] = t("Cannot enable that account; that account type is disabled.");
        } else {
            // reset all failure fields
 /**
  * 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);
 }