12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\task;
- use app\task\time\DemoTime;
- use think\Cache;
- use think\Console;
- class Kernel{
-
- public function schedule()
- {
- $this->command(DemoTime::class,'1','minute');
- }
-
- private function command($class,string $daily = '',string $type = 'minute')
- {
-
- if (!in_array($type,['minute','at'])) {
- return false;
- }
- if (!empty($daily)) {
- switch ($type){
- case 'minute':
- $run_time = Cache::get("task_{$class}_{$type}_{$daily}");
- if (ceil((time() - $run_time) / 60) < $daily){
- return false;
- }
- Cache::set("task_{$class}_{$type}_{$daily}",time());
- break;
- case 'at':
- if (date('H:i') != $daily){
- return false;
- }
- break;
- default:
- return false;
- }
- }
- return (new $class)->execute();
- }
- }
|