Remove deletion queue for servers. Just immediately delete.

This commit is contained in:
Dane Everitt 2017-03-31 22:12:31 -04:00
parent 2dec659dd1
commit 536865b22a
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
16 changed files with 32 additions and 294 deletions

View file

@ -219,7 +219,7 @@ class ServerController extends BaseController
$repo = new ServerRepository;
try {
$repo->deleteServer($id, $force);
$repo->delete($id, is_null($force));
return $this->response->noContent();
} catch (DisplayException $ex) {

View file

@ -46,9 +46,7 @@ class ServersController extends Controller
*/
public function index(Request $request)
{
$servers = Models\Server::withTrashed()->with(
'node', 'user', 'allocation'
);
$servers = Models\Server::with('node', 'user', 'allocation');
if (! is_null($request->input('query'))) {
$servers->search($request->input('query'));
@ -146,7 +144,7 @@ class ServersController extends Controller
*/
public function viewIndex(Request $request, $id)
{
return view('admin.servers.view.index', ['server' => Models\Server::withTrashed()->findOrFail($id)]);
return view('admin.servers.view.index', ['server' => Models\Server::findOrFail($id)]);
}
/**
@ -238,7 +236,7 @@ class ServersController extends Controller
*/
public function viewDelete(Request $request, $id)
{
return view('admin.servers.view.delete', ['server' => Models\Server::withTrashed()->findOrFail($id)]);
return view('admin.servers.view.delete', ['server' => Models\Server::findOrFail($id)]);
}
/**
@ -420,49 +418,7 @@ class ServersController extends Controller
$repo = new ServerRepository;
try {
$repo->queueDeletion($id, ($request->input('is_force') > 0));
Alert::success('Server has been marked for deletion on the system.')->flash();
} catch (DisplayException $ex) {
Alert::danger($ex->getMessage())->flash();
} catch (\Exception $ex) {
Log::error($ex);
Alert::danger('An unhandled exception occured while attemping to delete this server. This error has been logged.')->flash();
}
return redirect()->route('admin.servers.view.delete', $id);
}
/**
* Cancels a pending server deletion request.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\RedirectResponse
*/
public function cancelDeletion(Request $request, $id)
{
$repo = new ServerRepository;
$repo->cancelDeletion($id);
Alert::success('Server deletion has been cancelled. This server will remain suspended until you unsuspend it.')->flash();
return redirect()->route('admin.servers.view.delete', $id);
}
/**
* Skips the queue and continues the server deletion process.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @param string $method
* @return \Illuminate\Http\RedirectResponse
*/
public function continueDeletion(Request $request, $id, $method = 'safe')
{
$repo = new ServerRepository;
try {
$repo->delete($id, (isset($method) && $method === 'force'));
$repo->delete($id, $request->has('force_delete'));
Alert::success('Server was successfully deleted from the system.')->flash();
return redirect()->route('admin.servers');

View file

@ -1,64 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Jobs;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Pterodactyl\Repositories\ServerRepository;
class DeleteServer extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* ID of server to be deleted.
*
* @var int
*/
protected $id;
/**
* Create a new job instance.
*
* @param int $id
* @return void
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$repo = new ServerRepository;
$repo->delete($this->id);
}
}

View file

@ -1,64 +0,0 @@
<?php
/**
* Pterodactyl - Panel
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
namespace Pterodactyl\Jobs;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Pterodactyl\Repositories\ServerRepository;
class SuspendServer extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* ID of associated server model.
*
* @var int
*/
protected $id;
/**
* Create a new job instance.
*
* @param int $id
* @return void
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$repo = new ServerRepository;
$repo->suspend($this->id, true);
}
}

View file

@ -30,12 +30,11 @@ use Carbon;
use Javascript;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Nicolaslopezj\Searchable\SearchableTrait;
class Server extends Model
{
use Notifiable, SearchableTrait, SoftDeletes;
use Notifiable, SearchableTrait;
/**
* The table associated with the model.

View file

@ -78,8 +78,6 @@ class ServerObserver
public function deleting(Server $server)
{
event(new Events\Server\Deleting($server));
$this->dispatch((new SuspendServer($server->id))->onQueue(config('pterodactyl.queues.high')));
}
/**
@ -91,12 +89,6 @@ class ServerObserver
public function deleted(Server $server)
{
event(new Events\Server\Deleted($server));
$this->dispatch(
(new DeleteServer($server->id))
->delay(Carbon::now()->addMinutes(config('pterodactyl.tasks.delete_server')))
->onQueue(config('pterodactyl.queues.standard'))
);
}
/**

View file

@ -719,25 +719,6 @@ class ServerRepository
});
}
/**
* Queue a server for deletion.
*
* @param int $id
* @param bool $force
* @return void
*/
public function queueDeletion($id, $force = false)
{
$server = Models\Server::findOrFail($id);
DB::transaction(function () use ($force, $server) {
$server->installed = $force ? 3 : $server->installed;
$server->save();
$server->delete();
});
}
/**
* Delete a server from the system permanetly.
*
@ -749,13 +730,7 @@ class ServerRepository
*/
public function delete($id, $force = false)
{
$server = Models\Server::withTrashed()->with('node', 'allocations', 'variables')->findOrFail($id);
// Handle server being restored previously or
// an accidental queue.
if (! $server->trashed()) {
return;
}
$server = Models\Server::with('node', 'allocations', 'variables')->findOrFail($id);
// Due to MySQL lockouts if the daemon response fails, we need to
// delete the server from the daemon first. If it succeedes and then
@ -768,7 +743,7 @@ class ServerRepository
'X-Access-Server' => $server->uuid,
])->request('DELETE', '/servers');
} catch (TransferException $ex) {
if ($server->installed !== 3 && ! $force) {
if (! $force) {
throw new DisplayException($ex->getMessage());
}
} catch (\Exception $ex) {
@ -807,25 +782,10 @@ class ServerRepository
}
// Fully delete the server.
$server->forceDelete();
$server->delete();
});
}
/**
* Cancel the deletion of a server.
*
* @param int $id
* @return void
*/
public function cancelDeletion($id)
{
$server = Models\Server::withTrashed()->findOrFail($id);
$server->restore();
$server->installed = 1;
$server->save();
}
/**
* Toggle the install status of a serve.
*
@ -856,7 +816,7 @@ class ServerRepository
*/
public function suspend($id, $deleted = false)
{
$server = Models\Server::withTrashed()->with('node')->findOrFail($id);
$server = Models\Server::with('node')->findOrFail($id);
DB::beginTransaction();