DatabaseJob.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Illuminate\Queue\Jobs;
  3. use Illuminate\Container\Container;
  4. use Illuminate\Queue\DatabaseQueue;
  5. use Illuminate\Contracts\Queue\Job as JobContract;
  6. class DatabaseJob extends Job implements JobContract
  7. {
  8. /**
  9. * The database queue instance.
  10. *
  11. * @var \Illuminate\Queue\DatabaseQueue
  12. */
  13. protected $database;
  14. /**
  15. * The database job payload.
  16. *
  17. * @var \stdClass
  18. */
  19. protected $job;
  20. /**
  21. * Create a new job instance.
  22. *
  23. * @param \Illuminate\Container\Container $container
  24. * @param \Illuminate\Queue\DatabaseQueue $database
  25. * @param \stdClass $job
  26. * @param string $connectionName
  27. * @param string $queue
  28. * @return void
  29. */
  30. public function __construct(Container $container, DatabaseQueue $database, $job, $connectionName, $queue)
  31. {
  32. $this->job = $job;
  33. $this->queue = $queue;
  34. $this->database = $database;
  35. $this->container = $container;
  36. $this->connectionName = $connectionName;
  37. }
  38. /**
  39. * Release the job back into the queue.
  40. *
  41. * @param int $delay
  42. * @return mixed
  43. */
  44. public function release($delay = 0)
  45. {
  46. parent::release($delay);
  47. $this->delete();
  48. return $this->database->release($this->queue, $this->job, $delay);
  49. }
  50. /**
  51. * Delete the job from the queue.
  52. *
  53. * @return void
  54. */
  55. public function delete()
  56. {
  57. parent::delete();
  58. $this->database->deleteReserved($this->queue, $this->job->id);
  59. }
  60. /**
  61. * Get the number of times the job has been attempted.
  62. *
  63. * @return int
  64. */
  65. public function attempts()
  66. {
  67. return (int) $this->job->attempts;
  68. }
  69. /**
  70. * Get the job identifier.
  71. *
  72. * @return string
  73. */
  74. public function getJobId()
  75. {
  76. return $this->job->id;
  77. }
  78. /**
  79. * Get the raw body string for the job.
  80. *
  81. * @return string
  82. */
  83. public function getRawBody()
  84. {
  85. return $this->job->payload;
  86. }
  87. }