我没有在我的模块中运行计划任务。我遵循了文档:
https://docs.shopware.com/en/shopware-platform-dev-en/how-to/scheduled-tasks
和:
https://docs.shopware.com/en/shopware-platform-dev-en/references-internals/core/module/tasks
但似乎任务永远不会运行(我添加了日志记录以确保)。该任务显示在“scheduled_task”数据库表中,状态为“queued”,last_execution_time 为“NULL”。然而,看起来其他计划任务(如 delete_newsletter_recipient_task、requeue_dead_messages、product_export_generate_task、shopware.sitemap_generate 和 shopware.elasticsearch.create.alias)正在运行。此外,如果我手动运行“DownloadFeedTaskHandler”“运行”方法,代码将按预期工作。
我发现这个(德语)论坛帖子或多或少有相同的问题,但没有解决方案:
https://forum.shopware.com/discussion/67988/scheduled-task-hat-den-queued-status
我检查了 dead_messages 表,但它没有任何记录。
知道如何从这里出发吗?
我的相关文件如下所示:
自定义/插件/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>
自定义/插件/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
}
}
自定义/插件/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";
}
}