Registering a new scheduled-task on plugin update

Viewed 29
1 Answers

Yes, the documentation seems to be misleading there currently. Until this is fixed, the "cleanest" approach would be to register an UpdateService in your plugin to re-register the tasks and use it in your update method:

<service id="Foo\MyPlugin\UpdateService" public="true">
    <argument type="service" id="Shopware\Core\Framework\MessageQueue\ScheduledTask\Registry\TaskRegistry"/>
</service>
namespace Foo\MyPlugin;

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

class UpdateService
{
    private TaskRegistry $taskRegistry;

    public function __construct(TaskRegistry $taskRegistry)
    {
        $this->taskRegistry = $taskRegistry;
    }

    public function registerTasks(): void
    {
        $this->taskRegistry->registerTasks();
    }
}
class MyPlugin extends Plugin
{
    public function update(UpdateContext $updateContext): void
    {
        $this->container->get(UpdateService::class)->registerTasks();
    }
}
Related