I don't get a scheduled task to run in my module. I followed the documentation:
https://docs.shopware.com/en/shopware-platform-dev-en/how-to/scheduled-tasks
and:
https://docs.shopware.com/en/shopware-platform-dev-en/references-internals/core/module/tasks
But it seems the task never runs (I added logging to make sure). The task is showing up in the 'scheduled_task' database table with the status 'queued' and a last_execution_time of 'NULL'. It looks like the other scheduled tasks (like the delete_newsletter_recipient_task, requeue_dead_messages, product_export_generate_task, shopware.sitemap_generate and shopware.elasticsearch.create.alias) are running however. Also if I manualy run the 'DownloadFeedTaskHandler' 'run' method the code is working as expected.
I found this (German) forum post with more or less the same problem, but no solution:
https://forum.shopware.com/discussion/67988/scheduled-task-hat-den-queued-status
I checked the dead_messages table but it doesn't have any records.
Any idea how to go from here?
My relevant files look like:
custom/plugins/AWSamplePlugin/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="AW\SamplePlugin\ScheduledTask\DownloadFeedTask">
<tag name="shopware.scheduled.task" />
</service>
<service id="AW\SamplePlugin\ScheduledTask\DownloadFeedTaskHandler">
<argument type="service" id="scheduled_task.repository" />
<argument type="service" id="Shopware\Core\System\SystemConfig\SystemConfigService" />
<argument type="service" id="logger" />
<argument type="service" id="sales_channel.repository" />
<tag name="messenger.message_handler" />
</service>
</services>
</container>
custom/plugins/AWSamplePlugin/src/ScheduledTask/DownloadFeedTask.php:
<?php declare(strict_types=1);
namespace AW\SamplePlugin\ScheduledTask;
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTask;
class DownloadFeedTask extends ScheduledTask
{
public static function getTaskName(): string
{
return 'aw.download_feed';
}
public static function getDefaultInterval(): int
{
return 60; // Every minute
}
}
custom/plugins/AWSamplePlugin/src/ScheduledTask/DownloadFeedTaskHandler.php:
<?php declare(strict_types=1);
namespace AW\SamplePlugin\ScheduledTask;
use Shopware\Core\Framework\MessageQueue\ScheduledTask\ScheduledTaskHandler;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
use Shopware\Core\System\SystemConfig\SystemConfigService;
use Psr\Log\LoggerInterface;
class DownloadFeedTaskHandler extends ScheduledTaskHandler
{
protected $systemConfigService;
protected $logger;
protected $salesChannelRepository;
public function __construct(
EntityRepositoryInterface $scheduledTaskRepository,
SystemConfigService $systemConfigService,
LoggerInterface $logger,
EntityRepositoryInterface $salesChannelRepository
) {
$logger->info('__construct');
parent::__construct($scheduledTaskRepository);
$this->systemConfigService = $systemConfigService;
$this->logger = $logger;
$this->salesChannelRepository = $salesChannelRepository;
$logger->info('__construct END');
}
public static function getHandledMessages(): iterable
{
return [ DownloadFeedTask::class ];
}
public function run(): void
{
$this->logger->info('RUNNING!');
echo "ScheduledTask run";
}
}