SystemCron.php 737 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\System\Cron;
  4. use SixShop\Core\Attribute\Cron;
  5. use think\Cache;
  6. use Workerman\Crontab\Crontab;
  7. readonly class SystemCron
  8. {
  9. public function __construct(private Cache $cache)
  10. {
  11. }
  12. #[Cron('1 * * * * *', 'system.cron')]
  13. public function onWorkerStart(): void
  14. {
  15. $crontabList = [];
  16. foreach (Crontab::getAll() as $item) {
  17. /* @var Crontab $item */
  18. $crontabList[] = [
  19. 'rule' => $item->getRule(),
  20. 'name' => $item->getName(),
  21. 'id' => $item->getId(),
  22. 'time' => date('Y-m-d H:i:s'),
  23. ];
  24. }
  25. $this->cache->set('crontab_list', $crontabList);
  26. }
  27. }