Clock example

use Symfony\Component\Scheduler\Exception\InvalidArgumentException;
use Symfony\Component\Scheduler\Generator\MessageGenerator;
use Symfony\Component\Scheduler\ScheduleProviderInterface;

/** * @implements TransportFactoryInterface<SchedulerTransport> */
class SchedulerTransportFactory implements TransportFactoryInterface
{
    public function __construct(
        private readonly ContainerInterface $scheduleProviders,
        private readonly ClockInterface $clock = new Clock(),
    ) {
    }

    public function createTransport(string $dsn, array $options, SerializerInterface $serializer): SchedulerTransport
    {
        if ('schedule://' === $dsn) {
            throw new InvalidArgumentException('The Schedule DSN must contains a name, e.g. "schedule://default".');
        }
        if (false === $scheduleName = parse_url($dsn, \PHP_URL_HOST)) {
            throw new InvalidArgumentException(sprintf('The given Schedule DSN "%s" is invalid.', $dsn));
        }
        
private \SplObjectStorage $unacks;

    /** * @param ReceiverInterface[] $receivers Where the key is the transport name */
    public function __construct(
        private array $receivers,
        private MessageBusInterface $bus,
        private ?EventDispatcherInterface $eventDispatcher = null,
        private ?LoggerInterface $logger = null,
        private ?array $rateLimiters = null,
        private ClockInterface $clock = new Clock(),
    ) {
        $this->metadata = new WorkerMetadata([
            'transportNames' => array_keys($receivers),
        ]);
        $this->unacks = new \SplObjectStorage();
    }

    /** * Receive the messages and dispatch them to the bus. * * Valid options are: * * sleep (default: 1000000): Time in microseconds to sleep after no messages are found * * queues: The queue names to consume from, instead of consuming from all queues. When this is used, all receivers must implement the QueueReceiverInterface */
#[Required]     public function setClock(ClockInterface $clock): void
    {
        $this->clock = $clock;
    }

    /** * @return DatePoint */
    protected function now(): \DateTimeImmutable
    {
        $now = ($this->clock ??= new Clock())->now();

        return $now instanceof DatePoint ? $now : DatePoint::createFromInterface($now);
    }
}
final class OidcTokenHandler implements AccessTokenHandlerInterface
{
    use OidcTrait;

    public function __construct(
        private Algorithm $signatureAlgorithm,
        private JWK $jwk,
        private string $audience,
        private array $issuers,
        private string $claim = 'sub',
        private ?LoggerInterface $logger = null,
        private ClockInterface $clock = new Clock()
    ) {
    }

    public function getUserBadgeFrom(string $accessToken): UserBadge
    {
        if (!class_exists(JWSVerifier::class) || !class_exists(Checker\HeaderCheckerManager::class)) {
            throw new \LogicException('You cannot use the "oidc" token handler since "web-token/jwt-signature" and "web-token/jwt-checker" are not installed. Try running "composer require web-token/jwt-signature web-token/jwt-checker".');
        }

        try {
            // Decode the token

    private array $generators = [];
    private int $index = 0;
    private bool $shouldStop = false;

    /** * @param iterable<Schedule> $schedules */
    public function __construct(
        private readonly array $handlers,
        array $schedules,
        private readonly ClockInterface $clock = new Clock(),
    ) {
        foreach ($schedules as $schedule) {
            $this->addSchedule($schedule);
        }
    }

    public function addSchedule(Schedule $schedule): void
    {
        $this->addMessageGenerator(new MessageGenerator($schedule, 'schedule_'.$this->index++, $this->clock));
    }

    
use Symfony\Component\Scheduler\Trigger\StatefulTriggerInterface;

final class MessageGenerator implements MessageGeneratorInterface
{
    private ?Schedule $schedule = null;
    private TriggerHeap $triggerHeap;
    private ?\DateTimeImmutable $waitUntil;

    public function __construct(
        private readonly ScheduleProviderInterface $scheduleProvider,
        private readonly string $name,
        private readonly ClockInterface $clock = new Clock(),
        private ?CheckpointInterface $checkpoint = null,
    ) {
        $this->waitUntil = new \DateTimeImmutable('@0');
    }

    /** * @return \Generator<MessageContext, object> */
    public function getMessages(): \Generator
    {
        $checkpoint = $this->checkpoint();

        
Home | Imprint | This part of the site doesn't use cookies.