Job.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\App\Models;
  3. /**
  4. * Class Job
  5. * @package ModulesGarden\ProxmoxAddon\App\Models
  6. * @method static $this waiting()
  7. * @method static $this finished()
  8. * @method $this ofJob($job)
  9. * @method $this ofHostingId($hostingId)
  10. * @method static $this ofParentId($parentId)
  11. * @method static $this ofId($parentId)
  12. * @method $this ofJobs($jobs)
  13. * @method $this ofCustomId($id)
  14. */
  15. class Job extends \ModulesGarden\ProxmoxAddon\Core\Queue\Models\Job
  16. {
  17. public function scopeOfJob($query, $job)
  18. {
  19. return $query->where("job", $job . '@handle');
  20. }
  21. public function scopeOfJobs($query, $jobs) {
  22. foreach ($jobs as &$job) {
  23. $job .= '@handle';
  24. }
  25. return $query->whereIn("job", $jobs);
  26. }
  27. public function scopeOfHostingId($query, $hostingId)
  28. {
  29. return $query->where("rel_id", $hostingId)
  30. ->where("rel_type", "hosting");
  31. }
  32. public function scopeOfCustomId($query, $id)
  33. {
  34. return $query->where("custom_id", $id);
  35. }
  36. public function scopeWaiting($query)
  37. {
  38. return $query->whereIn("status", ['waiting', "running", ""]);
  39. }
  40. public function scopeFinished($query)
  41. {
  42. return $query->where("status", "finished");
  43. }
  44. public function scopeOfParentId($query, $parentId)
  45. {
  46. return $query->where("parent_id", $parentId);
  47. }
  48. public function scopeOfId($query, $id)
  49. {
  50. return $query->where("id", $id);
  51. }
  52. }