You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.1 KiB

  1. <?php
  2. namespace App\Jobs;
  3. use Exception;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Queue\SerializesModels;
  6. use Illuminate\Queue\InteractsWithQueue;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. use Illuminate\Foundation\Bus\Dispatchable;
  9. class Example implements ShouldQueue
  10. {
  11. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  12. /**
  13. * 队列任务最大失败次数
  14. *
  15. * @var int
  16. */
  17. public $tries = 5;
  18. /**
  19. * 队列任务最大运行时长(秒)
  20. *
  21. * @var int
  22. */
  23. public $timeout = 120;
  24. /**
  25. * Create a new job instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. \Log::info('----Example Queue----');
  32. }
  33. /**
  34. * Execute the job.
  35. *
  36. * @return void
  37. */
  38. public function handle()
  39. {
  40. \Log::info('队列执行成功');
  41. }
  42. /**
  43. * 任务失败
  44. *
  45. * @param Exception $exception
  46. * @return void
  47. */
  48. public function failed(Exception $e)
  49. {
  50. // 发送失败通知
  51. \Log::info('队列执行失败');
  52. }
  53. }