-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #388 from MineTrax/develop
v6.0.0
- Loading branch information
Showing
407 changed files
with
13,614 additions
and
8,556 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Enums; | ||
|
||
use BenSampo\Enum\Enum; | ||
|
||
final class CommandQueueStatus extends Enum | ||
{ | ||
const PENDING = 'pending'; | ||
|
||
const RUNNING = 'running'; | ||
|
||
const FAILED = 'failed'; | ||
|
||
const CANCELLED = 'cancelled'; | ||
|
||
const DEFERRED = 'deferred'; | ||
|
||
const COMPLETED = 'completed'; | ||
|
||
public function toArray(): mixed | ||
{ | ||
return [ | ||
'key' => $this->key, | ||
'value' => $this->value, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Enums\CommandQueueStatus; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\CreateCommandQueueRequest; | ||
use App\Jobs\RunCommandQueueJob; | ||
use App\Jobs\RunCommandQueuesFromRequestJob; | ||
use App\Models\CommandQueue; | ||
use App\Models\Player; | ||
use App\Models\Server; | ||
use App\Queries\Filters\FilterMultipleFields; | ||
use Illuminate\Http\Request; | ||
use Inertia\Inertia; | ||
use Spatie\QueryBuilder\AllowedFilter; | ||
use Spatie\QueryBuilder\QueryBuilder; | ||
|
||
class CommandQueueController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$this->authorize('viewAny', CommandQueue::class); | ||
|
||
$perPage = request()->input('perPage', 10); | ||
if ($perPage > 100) { | ||
$perPage = 100; | ||
} | ||
|
||
$fields = [ | ||
'id', | ||
'command_id', | ||
'server_id', | ||
'parsed_command', | ||
'config', | ||
'status', | ||
'execute_at', | ||
'max_attempts', | ||
'attempts', | ||
'last_attempt_at', | ||
'output', | ||
'tag', | ||
'player_uuid', | ||
'user_id', | ||
'player_id', | ||
'created_at', | ||
'updated_at', | ||
]; | ||
|
||
$commandQueues = QueryBuilder::for(CommandQueue::class) | ||
->with(['server:id,name,hostname', 'player:id,uuid,username']) | ||
->allowedFilters([ | ||
...$fields, | ||
'server.name', | ||
'player.username', | ||
AllowedFilter::custom('q', new FilterMultipleFields([ | ||
'id', | ||
'parsed_command', | ||
'status', | ||
'output', | ||
'tag', | ||
'player_uuid', | ||
])), | ||
]) | ||
->allowedSorts($fields) | ||
->defaultSort('-updated_at') | ||
->simplePaginate($perPage) | ||
->withQueryString(); | ||
|
||
return Inertia::render('Admin/CommandQueue/IndexCommandQueue', [ | ||
'commandQueues' => $commandQueues, | ||
'filters' => request()->all(['perPage', 'sort', 'filter']), | ||
]); | ||
} | ||
|
||
public function create() | ||
{ | ||
$this->authorize('create', CommandQueue::class); | ||
|
||
$servers = Server::select(['id', 'name', 'hostname'])->whereNotNull('webquery_port')->get(); | ||
$players = Player::select(['id', 'uuid', 'username'])->get(); | ||
|
||
return Inertia::render('Admin/CommandQueue/CreateCommandQueue', [ | ||
'servers' => $servers, | ||
'players' => $players, | ||
]); | ||
} | ||
|
||
public function store(CreateCommandQueueRequest $request) | ||
{ | ||
RunCommandQueuesFromRequestJob::dispatch($request->collect(), $request->user()->id); | ||
|
||
return redirect()->back() | ||
->with(['toast' => ['type' => 'success', 'title' => __('Commands Scheduled!'), 'body' => __('Commands has been scheduled for execution. Check the status in Command History.'), 'milliseconds' => 5000]]); | ||
} | ||
|
||
public function destroy(Request $request) | ||
{ | ||
$request->validate([ | ||
'id' => 'required|int', | ||
]); | ||
|
||
$commandQueue = CommandQueue::findOrFail($request->id); | ||
$this->authorize('delete', $commandQueue); | ||
|
||
$commandQueue->delete(); | ||
|
||
return redirect()->route('admin.command-queue.index') | ||
->with(['toast' => ['type' => 'success', 'title' => __('Deleted!')]]); | ||
} | ||
|
||
public function retry(Request $request) | ||
{ | ||
$request->validate([ | ||
'id' => 'sometimes|required|int', | ||
]); | ||
|
||
if ($request->id) { | ||
$commandQueues = CommandQueue::where('id', $request->id)->get(); | ||
} else { | ||
$commandQueues = CommandQueue::whereIn('status', [ | ||
CommandQueueStatus::FAILED, | ||
CommandQueueStatus::CANCELLED, | ||
])->get(); | ||
} | ||
|
||
foreach ($commandQueues as $commandQueue) { | ||
if ($request->user()->cannot('retry', $commandQueue)) { | ||
continue; | ||
} | ||
$commandQueue->status = 'pending'; | ||
$commandQueue->save(); | ||
RunCommandQueueJob::dispatch($commandQueue); | ||
} | ||
|
||
return redirect()->route('admin.command-queue.index') | ||
->with(['toast' => ['type' => 'success', 'title' => __('Retried!'), 'body' => __('Command has been queued for retrying! Refresh the page after few seconds to check the status.')]]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.