Job.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\Queue\Models;
  3. use ModulesGarden\ProxmoxAddon\Core\Models\ExtendedEloquentModel;
  4. /**
  5. * Class Job
  6. * @package ModulesGarden\ProxmoxAddon\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_CANCELLED ='cancelled';
  23. const STATUS_FAILED ='failed';
  24. /**
  25. * @var string
  26. */
  27. protected $table = 'Job';
  28. /**
  29. * @return JobLog::class[]
  30. */
  31. public function logs()
  32. {
  33. return $this->hasMany(JobLog::class, 'job_id');
  34. }
  35. /**
  36. * @return Job::class[]
  37. */
  38. public function children()
  39. {
  40. return $this->hasMany(Job::class, 'parent_id');
  41. }
  42. /**
  43. * @return $this
  44. */
  45. public function setRunning()
  46. {
  47. $this->setStatus(self::STATUS_RUNNING);
  48. return $this;
  49. }
  50. /**
  51. * @return $this
  52. */
  53. public function setFinished()
  54. {
  55. $this->setStatus(self::STATUS_FINISHED);
  56. return $this;
  57. }
  58. /**
  59. * @return $this
  60. */
  61. public function setWaiting()
  62. {
  63. $this->setStatus(self::STATUS_WAITING);
  64. return $this;
  65. }
  66. /**
  67. * @return $this
  68. */
  69. public function setError()
  70. {
  71. $this->setStatus(self::STATUS_ERROR);
  72. return $this;
  73. }
  74. /**
  75. * @param $time
  76. * @return $this
  77. */
  78. public function setRetryAfter($time)
  79. {
  80. $this->retry_after = $time;
  81. $this->save();
  82. return $this;
  83. }
  84. /**
  85. * @param $status
  86. * @return $this
  87. */
  88. public function setStatus($status)
  89. {
  90. $this->status = $status;
  91. $this->save();
  92. return $this;
  93. }
  94. /**
  95. * @return $this
  96. */
  97. public function increaseRetryCount()
  98. {
  99. $this->retry_count++;
  100. $this->save();
  101. return $this;
  102. }
  103. }