|
7 | 7 | use Carbon\CarbonImmutable; |
8 | 8 | use Pterodactyl\Models\Task; |
9 | 9 | use InvalidArgumentException; |
| 10 | +use Illuminate\Http\Response; |
10 | 11 | use Pterodactyl\Models\Schedule; |
11 | 12 | use Illuminate\Queue\SerializesModels; |
12 | 13 | use Illuminate\Queue\InteractsWithQueue; |
|
15 | 16 | use Pterodactyl\Services\Backups\InitiateBackupService; |
16 | 17 | use Pterodactyl\Repositories\Wings\DaemonPowerRepository; |
17 | 18 | use Pterodactyl\Repositories\Wings\DaemonCommandRepository; |
| 19 | +use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException; |
18 | 20 |
|
19 | 21 | class RunTaskJob extends Job implements ShouldQueue |
20 | 22 | { |
@@ -62,18 +64,32 @@ public function handle( |
62 | 64 |
|
63 | 65 | $server = $this->task->server; |
64 | 66 | // Perform the provided task against the daemon. |
65 | | - switch ($this->task->action) { |
66 | | - case 'power': |
67 | | - $powerRepository->setServer($server)->send($this->task->payload); |
68 | | - break; |
69 | | - case 'command': |
70 | | - $commandRepository->setServer($server)->send($this->task->payload); |
71 | | - break; |
72 | | - case 'backup': |
73 | | - $backupService->setIgnoredFiles(explode(PHP_EOL, $this->task->payload))->handle($server, null, true); |
74 | | - break; |
75 | | - default: |
76 | | - throw new InvalidArgumentException('Cannot run a task that points to a non-existent action.'); |
| 67 | + try { |
| 68 | + switch ($this->task->action) { |
| 69 | + case Task::ACTION_POWER: |
| 70 | + $powerRepository->setServer($server)->send($this->task->payload); |
| 71 | + break; |
| 72 | + case Task::ACTION_COMMAND: |
| 73 | + $commandRepository->setServer($server)->send($this->task->payload); |
| 74 | + break; |
| 75 | + case Task::ACTION_BACKUP: |
| 76 | + $backupService->setIgnoredFiles(explode(PHP_EOL, $this->task->payload))->handle($server, null, true); |
| 77 | + break; |
| 78 | + default: |
| 79 | + throw new InvalidArgumentException('Cannot run a task that points to a non-existent action.'); |
| 80 | + } |
| 81 | + } catch (Exception $exception) { |
| 82 | + if ($exception instanceof DaemonConnectionException) { |
| 83 | + // If the task "failed" because the server is offline and it was sending a command or |
| 84 | + // executing a power action (which shouldn't happen?) then just stop trying to process |
| 85 | + // the schedule, but don't actually log the failure. |
| 86 | + if ($this->task->action === Task::ACTION_POWER || $this->task->action === Task::ACTION_COMMAND) { |
| 87 | + // Do the thing |
| 88 | + if ($exception->getStatusCode() === Response::HTTP_CONFLICT) { |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + throw $exception; |
77 | 93 | } |
78 | 94 |
|
79 | 95 | $this->markTaskNotQueued(); |
|
0 commit comments