Bladeren bron

install the symfony scheduler

Olivier Massot 3 maanden geleden
bovenliggende
commit
e0a6c909d2
2 gewijzigde bestanden met toevoegingen van 29 en 0 verwijderingen
  1. 1 0
      composer.json
  2. 28 0
      src/Schedule.php

+ 1 - 0
composer.json

@@ -60,6 +60,7 @@
     "symfony/polyfill-intl-messageformatter": "^1.24",
     "symfony/property-access": "7.3.*",
     "symfony/property-info": "7.3.*",
+    "symfony/scheduler": "7.3.*",
     "symfony/security-bundle": "7.3.*",
     "symfony/serializer": "7.3.*",
     "symfony/translation": "7.3.*",

+ 28 - 0
src/Schedule.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace App;
+
+use Symfony\Component\Scheduler\Attribute\AsSchedule;
+use Symfony\Component\Scheduler\Schedule as SymfonySchedule;
+use Symfony\Component\Scheduler\ScheduleProviderInterface;
+use Symfony\Contracts\Cache\CacheInterface;
+
+#[AsSchedule]
+class Schedule implements ScheduleProviderInterface
+{
+    public function __construct(
+        private CacheInterface $cache,
+    ) {
+    }
+
+    public function getSchedule(): SymfonySchedule
+    {
+        return (new SymfonySchedule())
+            ->stateful($this->cache) // ensure missed tasks are executed
+            ->processOnlyLastMissedRun(true) // ensure only last missed task is run
+
+            // add your own tasks here
+            // see https://symfony.com/doc/current/scheduler.html#attaching-recurring-messages-to-a-schedule
+        ;
+    }
+}