ProcessActiveSkillsCommand.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Module\Pet\Console;
  3. use App\Module\Pet\Jobs\ProcessActiveSkillsJob;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Log;
  6. /**
  7. * 处理宠物激活技能的定时命令
  8. *
  9. * 每分钟执行一次,处理所有激活中的宠物技能
  10. */
  11. class ProcessActiveSkillsCommand extends Command
  12. {
  13. /**
  14. * 命令签名
  15. *
  16. * @var string
  17. */
  18. protected $signature = 'pet:process-active-skills';
  19. /**
  20. * 命令描述
  21. *
  22. * @var string
  23. */
  24. protected $description = '处理宠物激活技能的定时任务';
  25. /**
  26. * 执行命令
  27. *
  28. * @return int
  29. */
  30. public function handle()
  31. {
  32. $this->info('开始处理宠物激活技能...');
  33. try {
  34. // 分发任务到队列
  35. ProcessActiveSkillsJob::dispatch();
  36. $this->info('宠物激活技能处理任务已分发到队列');
  37. Log::info('宠物激活技能定时命令执行成功');
  38. return Command::SUCCESS;
  39. } catch (\Exception $e) {
  40. $this->error('处理宠物激活技能失败: ' . $e->getMessage());
  41. Log::error('宠物激活技能定时命令执行失败', [
  42. 'error' => $e->getMessage(),
  43. 'trace' => $e->getTraceAsString()
  44. ]);
  45. return Command::FAILURE;
  46. }
  47. }
  48. }