Example #1
0
 /**
  * {@inheritdoc}
  */
 public function commitDispatchedJobIds()
 {
     if ($queue_id = $this->getQueueId()) {
         if (!empty($this->dispatched_job_ids)) {
             $this->connection->transact(function () use($queue_id) {
                 $this->connection->execute('UPDATE `' . MySqlQueue::BATCHES_TABLE_NAME . '` SET `jobs_count` = `jobs_count` + ? WHERE `id` = ?', count($this->dispatched_job_ids), $queue_id);
             });
         }
     } else {
         throw new RuntimeException("Can't commit dispatched job ID-s in an unsaved batch");
     }
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function restoreFailedJobById($job_id, array $update_data = null)
 {
     $job = null;
     if ($row = $this->connection->executeFirstRow('SELECT `type`, `channel`, `data` FROM `' . self::FAILED_JOBS_TABLE_NAME . '` WHERE `id` = ?', $job_id)) {
         $this->connection->transact(function () use(&$job, $job_id, $update_data, $row) {
             $job_type = $row['type'];
             if (!class_exists($job_type)) {
                 throw new RuntimeException("Can't restore a job. Type '{$job_type}' not found");
             }
             $channel = $row['channel'];
             if (empty($channel)) {
                 $channel = QueueInterface::MAIN_CHANNEL;
             }
             if ($row['data']) {
                 if (mb_substr($row['data'], 0, 1) == '{') {
                     $data = $this->jsonDecode($row['data']);
                 } else {
                     $data = unserialize($row['data']);
                 }
             }
             if (empty($data)) {
                 $data = [];
             }
             if ($update_data && is_array($update_data) && count($update_data)) {
                 $data = array_merge($data, $update_data);
             }
             $job = new $job_type($data);
             $this->enqueue($job, $channel);
             $this->connection->execute('DELETE FROM `' . self::FAILED_JOBS_TABLE_NAME . '` WHERE `id` = ?', $job_id);
         });
     } else {
         throw new RuntimeException("Failed job #{$job_id} not found");
     }
     return $job;
 }
 /**
  * {@inheritdoc}
  */
 public function setAllAsExecuted()
 {
     $this->connection->transact(function () {
         $timestamp = new DateTimeValue();
         $batch = $this->connection->batchInsert($this->getTableName(), ['migration', 'executed_at'], 50, ConnectionInterface::REPLACE);
         foreach ($this->getMigrations() as $migration) {
             $batch->insert(get_class($migration), $timestamp);
         }
         $batch->done();
     });
 }
Example #4
0
 /**
  * Delete specific object (and related objects if neccecery).
  *
  * @param  bool  $bulk
  * @return $this
  */
 public function &delete($bulk = false)
 {
     if ($this->isLoaded()) {
         $this->connection->transact(function () use($bulk) {
             $this->triggerEvent('on_before_delete', [$bulk]);
             $this->connection->delete($this->table_name, $this->getWherePartById($this->getId()));
             $this->is_new = true;
             $this->triggerEvent('on_after_delete', [$bulk]);
         });
     }
     return $this;
 }