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));
 }
 public static function addMetric($metric, $value, $distinct_id = null)
 {
     return self::$client->addMetric($metric, $value, $distinct_id);
 }