Final Class Yiisoft\Queue\Adapter\SynchronousAdapter
| Inheritance | Yiisoft\Queue\Adapter\SynchronousAdapter |
|---|---|
| Implements | Yiisoft\Queue\Adapter\AdapterInterface |
Public Methods
Method Details
| public mixed __construct ( Yiisoft\Queue\Worker\WorkerInterface $worker, Yiisoft\Queue\QueueInterface $queue ) | ||
| $worker | Yiisoft\Queue\Worker\WorkerInterface | |
| $queue | Yiisoft\Queue\QueueInterface | |
public function __construct(
private readonly WorkerInterface $worker,
private readonly QueueInterface $queue,
) {}
| public mixed __destruct ( ) |
public function __destruct()
{
$this->runExisting(function (MessageInterface $message): bool {
$this->worker->process($message, $this->queue);
return true;
});
}
| public Yiisoft\Queue\Message\MessageInterface push ( Yiisoft\Queue\Message\MessageInterface $message ) | ||
| $message | Yiisoft\Queue\Message\MessageInterface | |
public function push(MessageInterface $message): MessageInterface
{
$key = count($this->messages) + $this->current;
$this->messages[] = $message;
return new IdEnvelope($message, $key);
}
| public void runExisting ( callable $handlerCallback ) | ||
| $handlerCallback | callable | |
public function runExisting(callable $handlerCallback): void
{
$result = true;
while (isset($this->messages[$this->current]) && $result === true) {
$result = $handlerCallback($this->messages[$this->current]);
unset($this->messages[$this->current]);
$this->current++;
}
}
| public \Yiisoft\Queue\JobStatus status ( string|integer $id ) | ||
| $id | string|integer | |
public function status(string|int $id): JobStatus
{
$id = (int) $id;
if ($id < 0) {
throw new InvalidArgumentException('This adapter IDs start with 0.');
}
if ($id < $this->current) {
return JobStatus::DONE;
}
if (isset($this->messages[$id])) {
return JobStatus::WAITING;
}
throw new InvalidArgumentException('There is no message with the given ID.');
}
Signup or Login in order to comment.