Job.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace ModulesGarden\Servers\ProxmoxCloudVps\Core\Queue\Models;
  3. use ModulesGarden\Servers\ProxmoxCloudVps\Core\Models\ExtendedEloquentModel;
  4. /**
  5. * Class Job
  6. * @package ModulesGarden\Servers\ProxmoxCloudVps\Core\Job\Models
  7. * @version 1.0.1
  8. * @var $job
  9. * @var $data
  10. * @var $parent_id
  11. * @var $rel_type
  12. * @var $rel_id
  13. * @var $custom_id
  14. * @var $status
  15. */
  16. class Job extends ExtendedEloquentModel
  17. {
  18. const STATUS_RUNNING = 'running';
  19. const STATUS_FINISHED = 'finished';
  20. const STATUS_ERROR = 'error';
  21. const STATUS_WAITING = 'waiting';
  22. const STATUS_CANCELED = 'canceled';
  23. /**
  24. * @var string
  25. */
  26. protected $table = 'Job';
  27. /**
  28. * @return JobLog::class[]
  29. */
  30. public function logs()
  31. {
  32. return $this->hasMany(JobLog::class, 'job_id');
  33. }
  34. /**
  35. * @return Job::class[]
  36. */
  37. public function children()
  38. {
  39. return $this->hasMany(Job::class, 'parent_id');
  40. }
  41. /**
  42. * @return $this
  43. */
  44. public function setRunning()
  45. {
  46. $this->setStatus(self::STATUS_RUNNING);
  47. return $this;
  48. }
  49. /**
  50. * @return $this
  51. */
  52. public function setFinished()
  53. {
  54. $this->setStatus(self::STATUS_FINISHED);
  55. return $this;
  56. }
  57. /**
  58. * @return $this
  59. */
  60. public function setWaiting()
  61. {
  62. $this->setStatus(self::STATUS_WAITING);
  63. return $this;
  64. }
  65. /**
  66. * @return $this
  67. */
  68. public function setError()
  69. {
  70. $this->setStatus(self::STATUS_ERROR);
  71. return $this;
  72. }
  73. /**
  74. * @return $this
  75. */
  76. public function setCanceled()
  77. {
  78. $this->setStatus(self::STATUS_CANCELED);
  79. return $this;
  80. }
  81. /**
  82. * @param $time
  83. * @return $this
  84. */
  85. public function setRetryAfter($time)
  86. {
  87. $this->retry_after = $time;
  88. $this->save();
  89. return $this;
  90. }
  91. /**
  92. * @param $status
  93. * @return $this
  94. */
  95. public function setStatus($status)
  96. {
  97. $this->status = $status;
  98. $this->save();
  99. return $this;
  100. }
  101. /**
  102. * @return $this
  103. */
  104. public function increaseRetryCount()
  105. {
  106. $this->retry_count++;
  107. $this->save();
  108. return $this;
  109. }
  110. }