misc_pterodactyl-panel/app/Services/Schedules/Tasks/RunTaskService.php

54 lines
1.4 KiB
PHP
Raw Normal View History

2017-09-17 04:10:00 +00:00
<?php
2017-09-26 02:43:01 +00:00
/**
2017-09-17 04:10:00 +00:00
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
2017-09-26 02:43:01 +00:00
* This software is licensed under the terms of the MIT license.
* https://opensource.org/licenses/MIT
2017-09-17 04:10:00 +00:00
*/
namespace Pterodactyl\Services\Schedules\Tasks;
use Pterodactyl\Models\Task;
use Pterodactyl\Jobs\Schedule\RunTaskJob;
2017-09-27 03:16:26 +00:00
use Illuminate\Foundation\Bus\DispatchesJobs;
2017-09-17 04:10:00 +00:00
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
class RunTaskService
{
2017-09-27 03:16:26 +00:00
use DispatchesJobs;
2017-09-17 04:10:00 +00:00
/**
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
*/
protected $repository;
/**
* RunTaskService constructor.
*
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $repository
*/
2017-09-27 03:16:26 +00:00
public function __construct(TaskRepositoryInterface $repository)
{
2017-09-17 04:10:00 +00:00
$this->repository = $repository;
}
/**
* Push a single task onto the queue.
*
* @param int|\Pterodactyl\Models\Task $task
*
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
*/
public function handle($task)
{
if (! $task instanceof Task) {
$task = $this->repository->find($task);
}
$this->repository->update($task->id, ['is_queued' => true]);
2017-09-27 03:16:26 +00:00
$this->dispatch((new RunTaskJob($task->id, $task->schedule_id))->delay($task->time_offset));
2017-09-17 04:10:00 +00:00
}
}