InteractsWithQueue.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Illuminate\Queue;
  3. use Illuminate\Contracts\Queue\Job as JobContract;
  4. trait InteractsWithQueue
  5. {
  6. /**
  7. * The underlying queue job instance.
  8. *
  9. * @var \Illuminate\Contracts\Queue\Job
  10. */
  11. protected $job;
  12. /**
  13. * Get the number of times the job has been attempted.
  14. *
  15. * @return int
  16. */
  17. public function attempts()
  18. {
  19. return $this->job ? $this->job->attempts() : 1;
  20. }
  21. /**
  22. * Delete the job from the queue.
  23. *
  24. * @return void
  25. */
  26. public function delete()
  27. {
  28. if ($this->job) {
  29. return $this->job->delete();
  30. }
  31. }
  32. /**
  33. * Fail the job from the queue.
  34. *
  35. * @param \Throwable $exception
  36. * @return void
  37. */
  38. public function fail($exception = null)
  39. {
  40. if ($this->job) {
  41. FailingJob::handle($this->job->getConnectionName(), $this->job, $exception);
  42. }
  43. }
  44. /**
  45. * Release the job back into the queue.
  46. *
  47. * @param int $delay
  48. * @return void
  49. */
  50. public function release($delay = 0)
  51. {
  52. if ($this->job) {
  53. return $this->job->release($delay);
  54. }
  55. }
  56. /**
  57. * Set the base queue job instance.
  58. *
  59. * @param \Illuminate\Contracts\Queue\Job $job
  60. * @return $this
  61. */
  62. public function setJob(JobContract $job)
  63. {
  64. $this->job = $job;
  65. return $this;
  66. }
  67. }