summaryrefslogtreecommitdiffstatshomepage
path: root/core/lib/Drupal/Core/Queue/SuspendQueueException.php
blob: 37ed2874c67ed6b4f371a0d7831672d5f97ddd42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php

namespace Drupal\Core\Queue;

/**
 * Exception class to throw to indicate that a cron queue should be skipped.
 *
 * An implementation of \Drupal\Core\Queue\QueueWorkerInterface::processItem()
 * throws this class of exception to indicate that processing of the whole queue
 * should be skipped. This should be thrown rather than a normal Exception if
 * the problem encountered by the queue worker is such that it can be deduced
 * that workers of subsequent items would encounter it too. For example, if a
 * remote site that the queue worker depends on appears to be inaccessible.
 */
class SuspendQueueException extends \RuntimeException {

  /**
   * Seconds to wait before resuming the queue, or NULL if unknown.
   *
   * @var float|null
   */
  protected $delay = NULL;

  /**
   * Constructs a SuspendQueueException.
   *
   * @param string $message
   *   The error message.
   * @param int $code
   *   The error code.
   * @param \Throwable|null $previous
   *   The previous throwable used for the exception chaining.
   * @param float|null $delay
   *   If the time for when the queue will be ready to resume processing is
   *   known, pass an interval in seconds. Otherwise NULL if the time to resume
   *   processing the queue is not known.
   */
  public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = NULL, ?float $delay = NULL) {
    parent::__construct($message, $code, $previous);
    $this->delay = $delay;
  }

  /**
   * Get the desired delay interval for this item.
   *
   * @return float|null
   *   If the time for when the queue will be ready to resume processing is
   *   known, pass an interval in seconds. Otherwise NULL if the time to resume
   *   processing the queue is not known.
   */
  public function getDelay(): ?float {
    return $this->delay;
  }

  /**
   * Determine whether the next time the queue should be checked is known.
   *
   * @return bool
   *   Whether the time to resume processing the queue is known.
   */
  public function isDelayable(): bool {
    return isset($this->delay);
  }

}