|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace OnHover\RunCloud\Actions; |
| 4 | + |
| 5 | +use OnHover\RunCloud\Resources\SupervisorJob; |
| 6 | + |
| 7 | + |
| 8 | +trait ManagesSupervisor |
| 9 | +{ |
| 10 | + |
| 11 | + |
| 12 | + /** |
| 13 | + * List binaries |
| 14 | + * |
| 15 | + * @param int $serverId |
| 16 | + * @return [] |
| 17 | + * |
| 18 | + */ |
| 19 | + public function supervisorBinaries(int $serverId) |
| 20 | + { |
| 21 | + $binaries = $this->get("servers/{$serverId}/supervisors/binaries"); |
| 22 | + return $binaries; |
| 23 | + } |
| 24 | + |
| 25 | + |
| 26 | + /** |
| 27 | + * Create new Supervisor job |
| 28 | + * |
| 29 | + * @param int $serverId |
| 30 | + * @param array $data |
| 31 | + * @return SupervisorJob |
| 32 | + * |
| 33 | + */ |
| 34 | + public function createSupervisorJob(int $serverId, array $data) |
| 35 | + { |
| 36 | + $job = $this->post("servers/{$serverId}/supervisors", $data); |
| 37 | + return new SupervisorJob($job, $this); |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + /** |
| 42 | + * List all jobs |
| 43 | + * |
| 44 | + * @param int $serverId |
| 45 | + * @param array $params |
| 46 | + * @return SupervisorJob[] |
| 47 | + * |
| 48 | + */ |
| 49 | + public function supervisorJobs(int $serverId, string $search = '') |
| 50 | + { |
| 51 | + $data = $this->getAllData("servers/{$serverId}/supervisors", ['search' => $search]); |
| 52 | + return $this->transformCollection($data, SupervisorJob::class); |
| 53 | + } |
| 54 | + |
| 55 | + |
| 56 | + /** |
| 57 | + * Get one job |
| 58 | + * |
| 59 | + * @param int $serverId |
| 60 | + * @param int $jobId |
| 61 | + * @return SupervisorJob |
| 62 | + * |
| 63 | + */ |
| 64 | + public function supervisorJob(int $serverId, int $jobId) |
| 65 | + { |
| 66 | + $job = $this->get("servers/{$serverId}/supervisors/{$jobId}"); |
| 67 | + return new SupervisorJob($job, $this); |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | + /** |
| 72 | + * Get job status |
| 73 | + * |
| 74 | + * @param int $serverId |
| 75 | + * @return [] |
| 76 | + * |
| 77 | + */ |
| 78 | + public function supervisorStatus(int $serverId) |
| 79 | + { |
| 80 | + $response = $this->get("servers/{$serverId}/supervisors/status"); |
| 81 | + return $response; |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + /** |
| 86 | + * Rebuild jobs |
| 87 | + * |
| 88 | + * @param int $serverId |
| 89 | + * @return string |
| 90 | + * |
| 91 | + */ |
| 92 | + public function rebuildSupervisorJobs(int $serverId) |
| 93 | + { |
| 94 | + $response = $this->post("servers/{$serverId}/supervisors/rebuild"); |
| 95 | + return $response; |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | + /** |
| 100 | + * Reload job |
| 101 | + * |
| 102 | + * @param int $serverId |
| 103 | + * @return SupervisorJob |
| 104 | + * |
| 105 | + */ |
| 106 | + public function reloadSupervisorJob(int $serverId, int $jobId) |
| 107 | + { |
| 108 | + $job = $this->post("servers/{$serverId}/supervisors/{$jobId}/reload"); |
| 109 | + return new SupervisorJob($job, $this); |
| 110 | + } |
| 111 | + |
| 112 | + |
| 113 | + /** |
| 114 | + * Delete job |
| 115 | + * |
| 116 | + * @param int $serverId |
| 117 | + * @param int $jobId |
| 118 | + * @return SupervisorJob |
| 119 | + * |
| 120 | + */ |
| 121 | + public function deleteSupervisorJob(int $serverId, int $jobId) |
| 122 | + { |
| 123 | + $job = $this->delete("servers/{$serverId}/supervisors/{$jobId}"); |
| 124 | + return new SupervisorJob($job, $this); |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | +} |
0 commit comments