vendor/shopware/core/Framework/MessageQueue/ScheduledTask/Api/ScheduledTaskController.php line 52

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\MessageQueue\ScheduledTask\Api;
  3. use OpenApi\Annotations as OA;
  4. use Shopware\Core\Framework\MessageQueue\ScheduledTask\Scheduler\TaskScheduler;
  5. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  6. use Shopware\Core\Framework\Routing\Annotation\Since;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. /**
  11.  * @Route(defaults={"_routeScope"={"api"}})
  12.  */
  13. class ScheduledTaskController extends AbstractController
  14. {
  15.     /**
  16.      * @var TaskScheduler
  17.      */
  18.     private $taskScheduler;
  19.     public function __construct(TaskScheduler $taskScheduler)
  20.     {
  21.         $this->taskScheduler $taskScheduler;
  22.     }
  23.     /**
  24.      * @Since("6.0.0.0")
  25.      * @OA\Post(
  26.      *     path="/_action/scheduled-task/run",
  27.      *     summary="Run scheduled tasks.",
  28.      *     description="Starts the scheduled task worker to handle the next scheduled tasks.",
  29.      *     operationId="runScheduledTasks",
  30.      *     tags={"Admin API", "System Operations"},
  31.      *     @OA\Response(
  32.      *         response="200",
  33.      *         description="Returns a success message indicating a successful run.",
  34.      *         @OA\JsonContent(
  35.      *               @OA\Property(
  36.      *                  property="message",
  37.      *                  description="Success message",
  38.      *                  type="string"
  39.      *              )
  40.      *         )
  41.      *     )
  42.      * )
  43.      * @Route("/api/_action/scheduled-task/run", name="api.action.scheduled-task.run", methods={"POST"})
  44.      */
  45.     public function runScheduledTasks(): JsonResponse
  46.     {
  47.         $this->taskScheduler->queueScheduledTasks();
  48.         return $this->json(['message' => 'Success']);
  49.     }
  50.     /**
  51.      * @Since("6.0.0.0")
  52.      * @OA\Get(
  53.      *     path="/_action/scheduled-task/min-run-interval",
  54.      *     summary="Get the minimum schedules task interval",
  55.      *     description="Fetches the smallest interval that a scheduled task uses.",
  56.      *     operationId="getMinRunInterval",
  57.      *     tags={"Admin API", "System Operations"},
  58.      *     @OA\Response(
  59.      *         response="200",
  60.      *         description="Returns the minimum interval.",
  61.      *         @OA\JsonContent(
  62.      *               @OA\Property(
  63.      *                  property="minRunInterval",
  64.      *                  description="Minimal interval in seconds.",
  65.      *                  type="string"
  66.      *              )
  67.      *         )
  68.      *     )
  69.      * )
  70.      * @Route("/api/_action/scheduled-task/min-run-interval", name="api.action.scheduled-task.min-run-interval", methods={"GET"})
  71.      */
  72.     public function getMinRunInterval(): JsonResponse
  73.     {
  74.         return $this->json(['minRunInterval' => $this->taskScheduler->getMinRunInterval()]);
  75.     }
  76. }