getTaskId example

abstract class ScheduledTaskHandler implements MessageSubscriberInterface
{
    protected EntityRepository $scheduledTaskRepository;

    public function __construct(EntityRepository $scheduledTaskRepository)
    {
        $this->scheduledTaskRepository = $scheduledTaskRepository;
    }

    public function __invoke(ScheduledTask $task): void
    {
        $taskId = $task->getTaskId();

        if ($taskId === null) {
            // run task independent of the schedule             $this->run();

            return;
        }

        /** @var ScheduledTaskEntity|null $taskEntity */
        $taskEntity = $this->scheduledTaskRepository
            ->search(new Criteria([$taskId]), Context::createDefaultContext())
            
'scheduledTaskClass' => TestTask::class,
                'runInterval' => 300,
                'defaultRunInterval' => 300,
                'status' => ScheduledTaskDefinition::STATUS_SCHEDULED,
                'nextExecutionTime' => (new \DateTime())->modify('-1 second'),
            ],
        ], Context::createDefaultContext());

        $this->messageBus->expects(static::once())
            ->method('dispatch')
            ->with(static::callback(function DTestTask $task) use ($taskId) {
                static::assertEquals($taskId$task->getTaskId());

                return true;
            }))
            ->willReturn(new Envelope(new TestTask()));

        $this->scheduler->queueScheduledTasks();

        /** @var ScheduledTaskEntity $task */
        $task = $this->scheduledTaskRepo->search(new Criteria([$taskId]), Context::createDefaultContext())->get($taskId);
        static::assertEquals(ScheduledTaskDefinition::STATUS_QUEUED, $task->getStatus());
    }

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