feat(demo): add story 1 — Sorano: Rock and Time
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Event;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
use Symfony\Component\Messenger\Stamp\StampInterface;
|
||||
|
||||
abstract class AbstractWorkerMessageEvent
|
||||
{
|
||||
private $envelope;
|
||||
private $receiverName;
|
||||
|
||||
public function __construct(Envelope $envelope, string $receiverName)
|
||||
{
|
||||
$this->envelope = $envelope;
|
||||
$this->receiverName = $receiverName;
|
||||
}
|
||||
|
||||
public function getEnvelope(): Envelope
|
||||
{
|
||||
return $this->envelope;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a unique identifier for transport receiver this message was received from.
|
||||
*/
|
||||
public function getReceiverName(): string
|
||||
{
|
||||
return $this->receiverName;
|
||||
}
|
||||
|
||||
public function addStamps(StampInterface ...$stamps): void
|
||||
{
|
||||
$this->envelope = $this->envelope->with(...$stamps);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Event;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
|
||||
/**
|
||||
* Event is dispatched before a message is sent to the transport.
|
||||
*
|
||||
* The event is *only* dispatched if the message will actually
|
||||
* be sent to at least one transport. If the message is sent
|
||||
* to multiple transports, the message is dispatched only one time.
|
||||
* This message is only dispatched the first time a message
|
||||
* is sent to a transport, not also if it is retried.
|
||||
*
|
||||
* @author Ryan Weaver <ryan@symfonycasts.com>
|
||||
*/
|
||||
final class SendMessageToTransportsEvent
|
||||
{
|
||||
private $envelope;
|
||||
|
||||
public function __construct(Envelope $envelope)
|
||||
{
|
||||
$this->envelope = $envelope;
|
||||
}
|
||||
|
||||
public function getEnvelope(): Envelope
|
||||
{
|
||||
return $this->envelope;
|
||||
}
|
||||
|
||||
public function setEnvelope(Envelope $envelope)
|
||||
{
|
||||
$this->envelope = $envelope;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Event;
|
||||
|
||||
use Symfony\Component\Messenger\Envelope;
|
||||
|
||||
/**
|
||||
* Dispatched when a message was received from a transport and handling failed.
|
||||
*
|
||||
* The event name is the class name.
|
||||
*/
|
||||
final class WorkerMessageFailedEvent extends AbstractWorkerMessageEvent
|
||||
{
|
||||
private $throwable;
|
||||
private $willRetry = false;
|
||||
|
||||
public function __construct(Envelope $envelope, string $receiverName, \Throwable $error)
|
||||
{
|
||||
$this->throwable = $error;
|
||||
|
||||
parent::__construct($envelope, $receiverName);
|
||||
}
|
||||
|
||||
public function getThrowable(): \Throwable
|
||||
{
|
||||
return $this->throwable;
|
||||
}
|
||||
|
||||
public function willRetry(): bool
|
||||
{
|
||||
return $this->willRetry;
|
||||
}
|
||||
|
||||
public function setForRetry(): void
|
||||
{
|
||||
$this->willRetry = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Event;
|
||||
|
||||
/**
|
||||
* Dispatched after a message was received from a transport and successfully handled.
|
||||
*
|
||||
* The event name is the class name.
|
||||
*/
|
||||
final class WorkerMessageHandledEvent extends AbstractWorkerMessageEvent
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Event;
|
||||
|
||||
/**
|
||||
* Dispatched when a message was received from a transport but before sent to the bus.
|
||||
*
|
||||
* The event name is the class name.
|
||||
*/
|
||||
final class WorkerMessageReceivedEvent extends AbstractWorkerMessageEvent
|
||||
{
|
||||
private $shouldHandle = true;
|
||||
|
||||
public function shouldHandle(?bool $shouldHandle = null): bool
|
||||
{
|
||||
if (null !== $shouldHandle) {
|
||||
$this->shouldHandle = $shouldHandle;
|
||||
}
|
||||
|
||||
return $this->shouldHandle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Event;
|
||||
|
||||
/**
|
||||
* Dispatched after a message has been sent for retry.
|
||||
*
|
||||
* The event name is the class name.
|
||||
*/
|
||||
final class WorkerMessageRetriedEvent extends AbstractWorkerMessageEvent
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Event;
|
||||
|
||||
use Symfony\Component\Messenger\Worker;
|
||||
|
||||
/**
|
||||
* Dispatched after the worker processed a message or didn't receive a message at all.
|
||||
*
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*/
|
||||
final class WorkerRunningEvent
|
||||
{
|
||||
private $worker;
|
||||
private $isWorkerIdle;
|
||||
|
||||
public function __construct(Worker $worker, bool $isWorkerIdle)
|
||||
{
|
||||
$this->worker = $worker;
|
||||
$this->isWorkerIdle = $isWorkerIdle;
|
||||
}
|
||||
|
||||
public function getWorker(): Worker
|
||||
{
|
||||
return $this->worker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when no message has been received by the worker.
|
||||
*/
|
||||
public function isWorkerIdle(): bool
|
||||
{
|
||||
return $this->isWorkerIdle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Event;
|
||||
|
||||
use Symfony\Component\Messenger\Worker;
|
||||
|
||||
/**
|
||||
* Dispatched when a worker has been started.
|
||||
*
|
||||
* @author Tobias Schultze <http://tobion.de>
|
||||
*/
|
||||
final class WorkerStartedEvent
|
||||
{
|
||||
private $worker;
|
||||
|
||||
public function __construct(Worker $worker)
|
||||
{
|
||||
$this->worker = $worker;
|
||||
}
|
||||
|
||||
public function getWorker(): Worker
|
||||
{
|
||||
return $this->worker;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Messenger\Event;
|
||||
|
||||
use Symfony\Component\Messenger\Worker;
|
||||
|
||||
/**
|
||||
* Dispatched when a worker has been stopped.
|
||||
*
|
||||
* @author Robin Chalas <robin.chalas@gmail.com>
|
||||
*/
|
||||
final class WorkerStoppedEvent
|
||||
{
|
||||
private $worker;
|
||||
|
||||
public function __construct(Worker $worker)
|
||||
{
|
||||
$this->worker = $worker;
|
||||
}
|
||||
|
||||
public function getWorker(): Worker
|
||||
{
|
||||
return $this->worker;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user