6.6.4: Scheduled Task run() method will nicht ausführen

Hi liebe Shopware Community,

wir versuchen seit Tagen in der 6.6.4 einen Scheduled Task zum Laufen zu bringen.

Dieser wird auch über systemd alle 15 min richtig scheduled; allerdings wird die run method nie ausgeführt und wir sind kurz vorm Verzweifeln ;( Docs, Videos, alles durch…

Habt ihr eine Idee? Beste Grüße

Task:
custom/plugins/EcomListing/src/Task/EcomListingTask.php

<?php declare(strict_types=1);

namespace EcomListing\Task;

use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTask;

class EcomListingTask extends ScheduledTask
{
    public static function getTaskName(): string
    {
        return 'ecom.listing';
    }

    public static function getDefaultInterval(): int
    {
        return 60 * 15; // 15 minutes
    }

    public static function shouldRescheduleOnFailure(): bool
    {
        return true;
    }
}

Task Handler
custom/plugins/EcomListing/src/Task/EcomListingTaskHandler.php

<?php declare(strict_types=1);

namespace EcomListing\Task;

use Psr\Log\LoggerInterface;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler;
use Doctrine\DBAL\Connection;

#[AsMessageHandler(handles: EcomListingTask::class)]
class EcomListingTaskHandler extends ScheduledTaskHandler
{
    public function __construct(
        EntityRepository $scheduledTaskRepository,
        private readonly LoggerInterface $logger,
        private readonly Connection $connection,
    ) {
        parent::__construct($scheduledTaskRepository, $logger);
        //$this->logger->info(EcomListingTask::getTaskName() . '----------> construct ');
    }

    public function run(): void
    {

        $this->logger->info(EcomListingTask::getTaskName() . '----------> run ');

        $query = $this->connection->createQueryBuilder();
        $query->update('product', 'p')
                     ->set('p.is_closeout', 1);

        try {
            $result = $query->executeQuery();
        } catch (\Doctrine\DBAL\Exception $err) {
            $this->logger->error($err->getMessage());
        }  

        $this->logger->info(EcomListingTask::getTaskName() . '----------> finished ');
    }
}

DI
custom/plugins/EcomListing/src/Resources/config/services.xml

<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <service id="EcomListing\Task\EcomListingTask">
            <tag name="shopware.scheduled.task"/>
        </service>

        <service id="EcomListing\Task\EcomListingTaskHandler">
            <argument type="service" id="scheduled_task.repository"/>
            <argument type="service" id="logger"/>
            <argument type="service" id="Doctrine\DBAL\Connection"/>
            <tag name="messenger.message_handler"/>
        </service>

    </services>

</container>

Dein EcomListingTaskHandler solte Attribute AsMessageHandler importieren:

use Symfony\Component\Messenger\Attribute\AsMessageHandler;

1 „Gefällt mir“

oh man… danke, danke - das wars!