Un-butcher task system.

This commit is contained in:
Dane Everitt 2017-04-15 13:52:43 -04:00
parent 0fe9a4566e
commit 7f1a97184b
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
12 changed files with 154 additions and 77 deletions

View file

@ -26,7 +26,10 @@ namespace Pterodactyl\Jobs;
use Cron;
use Carbon;
use Pterodactyl\Models;
use Pterodactyl\Models\Task;
use Pterodactyl\Models\User;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\TaskLog;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
@ -37,11 +40,6 @@ class SendScheduledTask extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* @var \Pterodactyl\Models\Server
*/
protected $server;
/**
* @var \Pterodactyl\Models\Task
*/
@ -52,13 +50,12 @@ class SendScheduledTask extends Job implements ShouldQueue
*
* @return void
*/
public function __construct(Models\Server $server, Models\Task $task)
public function __construct(Task $task)
{
$this->server = $server;
$this->task = $task;
$task->queued = 1;
$task->save();
$this->task->queued = true;
$this->task->save();
}
/**
@ -69,7 +66,7 @@ class SendScheduledTask extends Job implements ShouldQueue
public function handle()
{
$time = Carbon::now();
$log = new Models\TaskLog;
$log = new TaskLog;
if ($this->attempts() >= 1) {
// Just delete the job, we will attempt it again later anyways.
@ -78,12 +75,15 @@ class SendScheduledTask extends Job implements ShouldQueue
try {
if ($this->task->action === 'command') {
$repo = new CommandRepository($this->server);
$repo = new CommandRepository($this->task->server, $this->task->user);
$response = $repo->send($this->task->data);
} elseif ($this->task->action === 'power') {
$repo = new PowerRepository($this->server);
} else if ($this->task->action === 'power') {
$repo = new PowerRepository($this->task->server, $this->task->user);
$response = $repo->do($this->task->data);
} else {
throw new \Exception('Task type provided was not valid.');
}
$log->fill([
'task_id' => $this->task->id,
'run_time' => $time,
@ -109,7 +109,7 @@ class SendScheduledTask extends Job implements ShouldQueue
$this->task->fill([
'last_run' => $time,
'next_run' => $cron->getNextRunDate(),
'queued' => 0,
'queued' => false,
]);
$this->task->save();
$log->save();