如何在Shopware 6中安排任务6

发布于 2025-01-20 21:00:47 字数 327 浏览 4 评论 0 原文

我创建了一个自定义计划的任务。我也使用以下教程进行了注册: 但是,在我的数据库中,此任务的状态仍然是“排队”的,而不是“计划的”。这阻止了任务执行。如何解决这个问题?我目前正在Localhost工作。

I have created a custom scheduled task. I have registered it as well using the following tutorial:
https://developer.shopware.com/docs/guides/plugins/plugins/plugin-fundamentals/add-scheduled-task#overview
However, in my database, the status of this task is still "queued" instead of "scheduled". This stops the task from executing. How to fix this? I am currently working on localhost.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

別甾虛僞 2025-01-27 21:00:47

状态排队表示执行该任务的消息已分派到消息队列。如果状态没有自动改变,则表明现在工作线程执行了队列中的消息。

默认情况下(对于开发设置!)有一个 AdminWorker,只要在浏览器中打开了商店管理,它就会轮询并执行队列中的消息。您还可以通过 CLI 手动启动工作程序:

bin/console messenger:consume

您可以在 官方文档

Status queued means that a message to execute that task was dispatched to the message queue. If the status does not change automatically that indicates that now worker executed the messages from the queue.

By default (for dev setups!) there is a AdminWorker, which will poll and execute messages from the queue as long as the shopware administration is open in a browser. You can also start a worker manually per CLI:

bin/console messenger:consume

You can find more information how to work with the message queue and how to start workers in the official docs.

烧了回忆取暖 2025-01-27 21:00:47

我遇到了完全相同的问题。
创建并注册任务后,它在数据库中显示为“排队”,因此未执行。
通过手动将其更改为“计划”,然后将其执行一次,然后重新设置为“排队”。
当然,无法使用生产力。

我的错误是以下内容:
在services.xml中,我通过了处理程序的其他参数。
因此,我的处理程序具有 __ construct()方法。
但是,该类从“ ScheduleDtaskHandler”继承,该类别又具有构造函数,并期望参数“ scheduledtaskrepository”。
该存储库用于更新状态。

解决方案:

  1. services> services> services.xml 中注入服务 stere streduled_task.repository 中的自定义处理程序
  2. 呼叫的处理程序的构造方法: parent> parent :: __ construct :: __ construct($) scheduledtaskrepository);

最后,应该这样做:

<?php declare(strict_types=1);

class myCustomHandler extends ScheduledTaskHandler
{

    public function __construct(
        EntityRepository $scheduledTaskRepository,
        [...]
    ) {
        parent::__construct($scheduledTaskRepository);
        [...]
    }


    public static function getHandledMessages(): iterable
    {
        return [ MyCustomTask::class ];
    }

    public function run(): void
    {
        file_put_contents('test.txt', 'test');
    }
}

I had exactly the same problem.
After I had created and registered my task, it was displayed in the database as "queued" and accordingly not executed.
By manually changing it to "scheduled" it was then executed once and set back to "queued".
Of course unusable for productive use.

My error was the following:
In the services.xml I had passed additional parameters for my handler.
Accordingly my handler had a __construct() method.
However, the class inherits from "ScheduledTaskHandler" which in turn also has a constructor and expects the parameter "scheduledTaskRepository".
This repository is used to update the status.

The solution:

  1. inject the service scheduled_task.repository in the services.xml into your custom handler
  2. call in the construct method of the handler: parent::__construct($scheduledTaskRepository);.

In the end it should like this:

<?php declare(strict_types=1);

class myCustomHandler extends ScheduledTaskHandler
{

    public function __construct(
        EntityRepository $scheduledTaskRepository,
        [...]
    ) {
        parent::__construct($scheduledTaskRepository);
        [...]
    }


    public static function getHandledMessages(): iterable
    {
        return [ MyCustomTask::class ];
    }

    public function run(): void
    {
        file_put_contents('test.txt', 'test');
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文