DemoTask.php 680 B

123456789101112131415161718192021222324252627
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Task;
  4. use App\Master\Framework\Extend\BaseTask;
  5. use App\Utils\LogUtil;
  6. use Hyperf\Crontab\Annotation\Crontab;
  7. #[Crontab(rule: "*/5 * * * * *", name: "DemoTask", callback: "execute", memo: "定时任务示例 每5秒执行一次", enable: false)]
  8. class DemoTask extends BaseTask {
  9. //日志板块
  10. protected string $LOG_MODULE = 'DemoTask';
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function do(): bool
  16. {
  17. // 打印当前毫秒级时间戳
  18. LogUtil::info('do', $this->LOG_MODULE, __FUNCTION__, time_ms());
  19. return $this->success('执行成功');
  20. }
  21. }