symfony - Shopware 6 计划任务未运行

标签 symfony shopware shopware6

我没有在我的模块中运行计划任务。我遵循了文档:

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";
    }
}

最佳答案

当 ScheduledTask 停留在排队状态时,很可能该任务生成的消息未被处理。
要使用消息,请使用 bin/console messenger:consume ,您可以使用 -vv标志以查看已处理的消息。
有关如何使用消息的更多信息,请参阅 docs article .
这是必要的,因为 bin/console scheduled-task:run命令只会检查哪些计划任务需要运行并负责调度,但为了实际运行这些任务,该命令会将消息发送到消息队列,然后当您从队列中使用这些消息时,该任务就会被执行。

关于symfony - Shopware 6 计划任务未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62430163/

相关文章:

php - Shopware 6 如何正确添加数组作为 SearchResult 的扩展

shopware6 - 用于 mail_template 更新的 Shopware 6 webhook

mysql - 如何在 mysql 中使用 symfony 和 Doctrine 查看表中的分页?

php - Symfony 验证

php - 自定义 Shopware6 路由给出 "405 Method Not Allowed"

Shopware 6 命令 './psh.phar administration:build.' 不起作用

Shopware 6 购物车 API

javascript - VichUploader 和 CroppieJS : how to send a base64 cropped image to persist in Symfony 4

php - symfony 3 的缓存失效是如何工作的?

shopware - 更改 Shopware 中的前端语言和多国家/地区支持