public static function setup($api_key, $app_id, $distinct_id = null) { if (!self::$client) { self::$client = new RestfulMetrics_Client(); } self::$client->setApiKey($api_key); self::$client->setApplicationId($app_id); if ($distinct_id) { self::$client->setDistinctId($distinct_id); } }
public function run() { $this->_lockId = md5(uniqid(getmypid(), true)); $jobs = $this->_fetchJobs(); foreach ($jobs as $job) { try { $this->_client->setApplicationId($job['app_id']); $this->_client->addMetric($job['metric'], unserialize($job['value']), $job['distinct_id']); $this->_logCompletedJob($job); } catch (Exception $e) { $this->_pdo->prepare("UPDATE {$this->_table_jobs} SET attempts = attempts + 1, last_error = ? WHERE id = ?")->execute(array($e->getMessage(), $job['id'])); $this->_errors[] = $e->getMessage(); } } // Unlock locked jobs $this->_pdo->prepare("UPDATE {$this->_table_jobs} SET lock_id = NULL WHERE lock_id = ?")->execute(array($this->_lockId)); }