Update schedule process to allow toggling/triggering via UI

This commit is contained in:
Dane Everitt 2018-01-08 21:43:10 -06:00
parent 02fe49892d
commit 036bea2b94
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
18 changed files with 280 additions and 221 deletions

View file

@ -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 Tests\Unit\Jobs\Schedule;
@ -87,9 +80,10 @@ class RunTaskJobTest extends TestCase
$schedule = factory(Schedule::class)->make();
$task = factory(Task::class)->make(['action' => 'power', 'sequence_id' => 1]);
$task->setRelation('server', $server = factory(Server::class)->make());
$task->setRelation('schedule', $schedule);
$server->setRelation('user', factory(User::class)->make());
$this->taskRepository->shouldReceive('getTaskWithServer')->with($task->id)->once()->andReturn($task);
$this->taskRepository->shouldReceive('getTaskForJobProcess')->with($task->id)->once()->andReturn($task);
$this->keyProviderService->shouldReceive('handle')->with($server, $server->user)->once()->andReturn('123456');
$this->powerRepository->shouldReceive('setServer')->with($task->server)->once()->andReturnSelf()
->shouldReceive('setToken')->with('123456')->once()->andReturnSelf()
@ -116,9 +110,10 @@ class RunTaskJobTest extends TestCase
$schedule = factory(Schedule::class)->make();
$task = factory(Task::class)->make(['action' => 'command', 'sequence_id' => 1]);
$task->setRelation('server', $server = factory(Server::class)->make());
$task->setRelation('schedule', $schedule);
$server->setRelation('user', factory(User::class)->make());
$this->taskRepository->shouldReceive('getTaskWithServer')->with($task->id)->once()->andReturn($task);
$this->taskRepository->shouldReceive('getTaskForJobProcess')->with($task->id)->once()->andReturn($task);
$this->keyProviderService->shouldReceive('handle')->with($server, $server->user)->once()->andReturn('123456');
$this->commandRepository->shouldReceive('setServer')->with($task->server)->once()->andReturnSelf()
->shouldReceive('setToken')->with('123456')->once()->andReturnSelf()
@ -145,9 +140,10 @@ class RunTaskJobTest extends TestCase
$schedule = factory(Schedule::class)->make();
$task = factory(Task::class)->make(['action' => 'command', 'sequence_id' => 1]);
$task->setRelation('server', $server = factory(Server::class)->make());
$task->setRelation('schedule', $schedule);
$server->setRelation('user', factory(User::class)->make());
$this->taskRepository->shouldReceive('getTaskWithServer')->with($task->id)->once()->andReturn($task);
$this->taskRepository->shouldReceive('getTaskForJobProcess')->with($task->id)->once()->andReturn($task);
$this->keyProviderService->shouldReceive('handle')->with($server, $server->user)->once()->andReturn('123456');
$this->commandRepository->shouldReceive('setServer')->with($task->server)->once()->andReturnSelf()
->shouldReceive('setToken')->with('123456')->once()->andReturnSelf()
@ -176,19 +172,45 @@ class RunTaskJobTest extends TestCase
* Test that an exception is thrown if an invalid task action is supplied.
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Cannot run a task that points to a non-existant action.
* @expectedExceptionMessage Cannot run a task that points to a non-existent action.
*/
public function testInvalidActionPassedToJob()
{
$schedule = factory(Schedule::class)->make();
$task = factory(Task::class)->make(['action' => 'invalid', 'sequence_id' => 1]);
$task->setRelation('server', $server = factory(Server::class)->make());
$task->setRelation('schedule', $schedule);
$server->setRelation('user', factory(User::class)->make());
$this->taskRepository->shouldReceive('getTaskWithServer')->with($task->id)->once()->andReturn($task);
$this->taskRepository->shouldReceive('getTaskForJobProcess')->with($task->id)->once()->andReturn($task);
$this->getJobInstance($task->id, 1234);
}
/**
* Test that a schedule marked as disabled does not get processed.
*/
public function testScheduleMarkedAsDisabledDoesNotProcess()
{
$schedule = factory(Schedule::class)->make(['is_active' => false]);
$task = factory(Task::class)->make(['action' => 'invalid', 'sequence_id' => 1]);
$task->setRelation('server', $server = factory(Server::class)->make());
$task->setRelation('schedule', $schedule);
$server->setRelation('user', factory(User::class)->make());
$this->taskRepository->shouldReceive('getTaskForJobProcess')->with($task->id)->once()->andReturn($task);
$this->scheduleRepository->shouldReceive('withoutFreshModel->update')->with($schedule->id, [
'is_processing' => false,
'last_run_at' => Carbon::now()->toDateTimeString(),
])->once()->andReturn(1);
$this->taskRepository->shouldReceive('update')->with($task->id, ['is_queued' => false])->once()->andReturn(1);
$this->getJobInstance($task->id, $schedule->id);
$this->assertTrue(true);
}
/**
* Run the job using the mocks provided.
*