Merge branch 'develop' into feature/vue-serverview
This commit is contained in:
commit
5ca13839cf
110 changed files with 7190 additions and 2093 deletions
|
@ -1,11 +1,4 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Nodes;
|
||||
|
||||
|
@ -13,7 +6,6 @@ use Pterodactyl\Models\Node;
|
|||
use GuzzleHttp\Exception\ConnectException;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Pterodactyl\Traits\Services\ReturnsUpdatedModels;
|
||||
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
|
||||
use Pterodactyl\Exceptions\Http\Connection\DaemonConnectionException;
|
||||
use Pterodactyl\Exceptions\Service\Node\ConfigurationNotPersistedException;
|
||||
|
@ -21,8 +13,6 @@ use Pterodactyl\Contracts\Repository\Daemon\ConfigurationRepositoryInterface;
|
|||
|
||||
class NodeUpdateService
|
||||
{
|
||||
use ReturnsUpdatedModels;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Database\ConnectionInterface
|
||||
*/
|
||||
|
@ -60,7 +50,7 @@ class NodeUpdateService
|
|||
*
|
||||
* @param \Pterodactyl\Models\Node $node
|
||||
* @param array $data
|
||||
* @return \Pterodactyl\Models\Node|mixed
|
||||
* @return \Pterodactyl\Models\Node
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\DisplayException
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
|
@ -74,14 +64,10 @@ class NodeUpdateService
|
|||
}
|
||||
|
||||
$this->connection->beginTransaction();
|
||||
if ($this->getUpdatedModel()) {
|
||||
$response = $this->repository->update($node->id, $data);
|
||||
} else {
|
||||
$response = $this->repository->withoutFreshModel()->update($node->id, $data);
|
||||
}
|
||||
$updatedModel = $this->repository->update($node->id, $data);
|
||||
|
||||
try {
|
||||
$this->configRepository->setNode($node)->update();
|
||||
$this->configRepository->setNode($updatedModel)->update();
|
||||
$this->connection->commit();
|
||||
} catch (RequestException $exception) {
|
||||
// Failed to connect to the Daemon. Let's go ahead and save the configuration
|
||||
|
@ -95,6 +81,6 @@ class NodeUpdateService
|
|||
throw new DaemonConnectionException($exception);
|
||||
}
|
||||
|
||||
return $response;
|
||||
return $updatedModel;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,53 +2,45 @@
|
|||
|
||||
namespace Pterodactyl\Services\Schedules;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Cron\CronExpression;
|
||||
use Pterodactyl\Models\Schedule;
|
||||
use Pterodactyl\Services\Schedules\Tasks\RunTaskService;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Pterodactyl\Jobs\Schedule\RunTaskJob;
|
||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
||||
use Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface;
|
||||
|
||||
class ProcessScheduleService
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Bus\Dispatcher
|
||||
*/
|
||||
private $dispatcher;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
private $scheduleRepository;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Services\Schedules\Tasks\RunTaskService
|
||||
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
|
||||
*/
|
||||
private $runnerService;
|
||||
|
||||
/**
|
||||
* @var \Carbon\Carbon|null
|
||||
*/
|
||||
private $runTimeOverride;
|
||||
private $taskRepository;
|
||||
|
||||
/**
|
||||
* ProcessScheduleService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Services\Schedules\Tasks\RunTaskService $runnerService
|
||||
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $repository
|
||||
* @param \Illuminate\Contracts\Bus\Dispatcher $dispatcher
|
||||
* @param \Pterodactyl\Contracts\Repository\ScheduleRepositoryInterface $scheduleRepository
|
||||
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $taskRepository
|
||||
*/
|
||||
public function __construct(RunTaskService $runnerService, ScheduleRepositoryInterface $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->runnerService = $runnerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the time that this schedule should be run at. This will override the time
|
||||
* defined on the schedule itself. Useful for triggering one-off task runs.
|
||||
*
|
||||
* @param \Carbon\Carbon $time
|
||||
* @return $this
|
||||
*/
|
||||
public function setRunTimeOverride(Carbon $time)
|
||||
{
|
||||
$this->runTimeOverride = $time;
|
||||
|
||||
return $this;
|
||||
public function __construct(
|
||||
Dispatcher $dispatcher,
|
||||
ScheduleRepositoryInterface $scheduleRepository,
|
||||
TaskRepositoryInterface $taskRepository
|
||||
) {
|
||||
$this->dispatcher = $dispatcher;
|
||||
$this->scheduleRepository = $scheduleRepository;
|
||||
$this->taskRepository = $taskRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,7 +53,10 @@ class ProcessScheduleService
|
|||
*/
|
||||
public function handle(Schedule $schedule)
|
||||
{
|
||||
$this->repository->loadTasks($schedule);
|
||||
$this->scheduleRepository->loadTasks($schedule);
|
||||
|
||||
/** @var \Pterodactyl\Models\Task $task */
|
||||
$task = $schedule->getRelation('tasks')->where('sequence_id', 1)->first();
|
||||
|
||||
$formattedCron = sprintf('%s %s %s * %s',
|
||||
$schedule->cron_minute,
|
||||
|
@ -70,27 +65,15 @@ class ProcessScheduleService
|
|||
$schedule->cron_day_of_week
|
||||
);
|
||||
|
||||
$this->repository->update($schedule->id, [
|
||||
$this->scheduleRepository->update($schedule->id, [
|
||||
'is_processing' => true,
|
||||
'next_run_at' => $this->getRunAtTime($formattedCron),
|
||||
'next_run_at' => CronExpression::factory($formattedCron)->getNextRunDate(),
|
||||
]);
|
||||
|
||||
$task = $schedule->getRelation('tasks')->where('sequence_id', 1)->first();
|
||||
$this->runnerService->handle($task);
|
||||
}
|
||||
$this->taskRepository->update($task->id, ['is_queued' => true]);
|
||||
|
||||
/**
|
||||
* Get the timestamp to store in the database as the next_run time for a schedule.
|
||||
*
|
||||
* @param string $formatted
|
||||
* @return \DateTime|string
|
||||
*/
|
||||
private function getRunAtTime(string $formatted)
|
||||
{
|
||||
if ($this->runTimeOverride instanceof Carbon) {
|
||||
return $this->runTimeOverride->toDateTimeString();
|
||||
}
|
||||
|
||||
return CronExpression::factory($formatted)->getNextRunDate();
|
||||
$this->dispatcher->dispatch(
|
||||
(new RunTaskJob($task->id, $schedule->id))->delay($task->time_offset)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Pterodactyl - Panel
|
||||
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
|
||||
*
|
||||
* This software is licensed under the terms of the MIT license.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
namespace Pterodactyl\Services\Schedules\Tasks;
|
||||
|
||||
use Pterodactyl\Models\Task;
|
||||
use Pterodactyl\Jobs\Schedule\RunTaskJob;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Pterodactyl\Contracts\Repository\TaskRepositoryInterface;
|
||||
|
||||
class RunTaskService
|
||||
{
|
||||
use DispatchesJobs;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\TaskRepositoryInterface
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
/**
|
||||
* RunTaskService constructor.
|
||||
*
|
||||
* @param \Pterodactyl\Contracts\Repository\TaskRepositoryInterface $repository
|
||||
*/
|
||||
public function __construct(TaskRepositoryInterface $repository)
|
||||
{
|
||||
$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]);
|
||||
$this->dispatch((new RunTaskJob($task->id, $task->schedule_id))->delay($task->time_offset));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue