You are here

class Progress in Ultimate Cron 8.2

Hierarchy

Expanded class hierarchy of Progress

1 string reference to 'Progress'
ultimate_cron.services.yml in ./ultimate_cron.services.yml
ultimate_cron.services.yml
1 service uses Progress
ultimate_cron.progress in ./ultimate_cron.services.yml
Drupal\ultimate_cron\Progress\Progress

File

src/Progress/Progress.php, line 8

Namespace

Drupal\ultimate_cron\Progress
View source
class Progress implements ProgressInterface {
  protected $progressUpdated = 0;
  protected $interval = 1;

  /**
   * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface
   */
  protected $keyValue;

  /**
   * Constructor.
   *
   * @param float $interval
   *   How often the database should be updated with the progress.
   */
  public function __construct(KeyValueFactoryInterface $key_value_factory, $interval = 1) {
    $this->keyValue = $key_value_factory
      ->get('uc-progress');
    $this->interval = $interval;
  }

  /**
   * {@inheritdoc}
   */
  public function getProgress($job_id) {
    $value = $this->keyValue
      ->get($job_id);
    return $value;
  }

  /**
   * {@inheritdoc}
   */
  public function getProgressMultiple($job_ids) {
    $values = $this->keyValue
      ->getMultiple($job_ids);
    return $values;
  }

  /**
   * {@inheritdoc}
   */
  public function setProgress($job_id, $progress) {
    if (microtime(TRUE) >= $this->progressUpdated + $this->interval) {
      $this->keyValue
        ->set($job_id, $progress);
      $this->progressUpdated = microtime(TRUE);
      return TRUE;
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Progress::$interval protected property
Progress::$keyValue protected property
Progress::$progressUpdated protected property
Progress::getProgress public function Get job progress. Overrides ProgressInterface::getProgress
Progress::getProgressMultiple public function Get multiple job progresses. Overrides ProgressInterface::getProgressMultiple
Progress::setProgress public function Set job progress. Overrides ProgressInterface::setProgress
Progress::__construct public function Constructor.