| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- /*
- * @Author: seven 7@seven.com
- * @Date: 2025-10-09 17:31:51
- * @LastEditors: seven 7@seven.com
- * @LastEditTime: 2025-11-05 11:37:34
- * @FilePath: \bot-28\app\Jobs\FiveSecondTaskJob.php
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- namespace App\Jobs;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldBeUnique;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- use App\Services\IssueService;
- use Illuminate\Support\Facades\Log;
- class FiveSecondTaskJob implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
- /**
- * 任务尝试次数
- */
- public $tries = 3;
- /**
- * 任务超时时间(秒)
- */
- public $timeout = 30;
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct()
- {
- //
- }
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- try {
- Log::error('🚀 开始执行15秒任务: ' . now());
-
- IssueService::syncCountdownIssue(); // 提前20秒提醒
- IssueService::syncCloseIssue(); // 同步停止
- // Log::error('✅ 获取到最新期号: ' . ($latestIssue ?? '无'));
- // 你的业务逻辑
- IssueService::getLatestIssue(); // 获取最新的期号
-
- // 重要:使用类名而不是 self(),避免递归
- FiveSecondTaskJob::dispatch()->delay(now()->addSeconds(15));
-
- Log::error('📅 下一个15秒任务已安排');
-
- } catch (\Exception $e) {
- Log::error('❌ 15秒任务执行异常: ' . $e->getMessage());
-
- // 异常后15秒重试
- FiveSecondTaskJob::dispatch()->delay(now()->addSeconds(15));
- }
- }
- // 可选:失败处理
- public function failed(\Throwable $exception)
- {
- Log::error('任务失败: ' . $exception->getMessage());
-
- // 可选:重新分发或通知
- dispatch(new self())->delay(now()->addSeconds(15));
- }
- }
|