Skip to content

Commit

Permalink
truncate player punishment and more UX fixes for queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Oct 26, 2024
1 parent e89697b commit 2f994d9
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/Http/Controllers/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use DB;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Cache;

class DashboardController extends Controller
{
Expand Down Expand Up @@ -65,6 +66,8 @@ public function index(Request $request)
'kpiPostCreatedForInterval' => $kpiPostCreatedForInterval,
'kpiTotalPostsPercent' => $kpiTotalPostsPercent,
'kpiTotalComments' => $kpiTotalComments,

'queueLastProcessed' => Cache::get('queue_last_processed'),
];
}

Expand Down
36 changes: 35 additions & 1 deletion app/Http/Controllers/Admin/Settings/DangerSettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace App\Http\Controllers\Admin\Settings;

use Illuminate\Support\Facades\Cache;
use App\Http\Controllers\Controller;
use App\Jobs\TruncatePlayerIntelJob;
use App\Jobs\TruncatePlayerPunishmentJob;
use App\Jobs\TruncateServerChatlogsJob;
use App\Jobs\TruncateServerConsolelogsJob;
use App\Jobs\TruncateServerIntelJob;
Expand All @@ -23,14 +25,25 @@ public function __construct()

public function show(): \Inertia\Response
{
return Inertia::render('Admin/Setting/DangerSetting');
return Inertia::render('Admin/Setting/DangerSetting', [
'inProgressList' => [
'truncateShouts' => Cache::get('dangerzone::truncate_shouts'),
'truncateConsolelogs' => Cache::get('dangerzone::truncate_consolelogs'),
'truncateChatlogs' => Cache::get('dangerzone::truncate_chatlogs'),
'truncatePlayerIntelData' => Cache::get('dangerzone::truncate_player_intel_data'),
'truncateServerIntelData' => Cache::get('dangerzone::truncate_server_intel_data'),
'truncatePlayerPunishments' => Cache::get('dangerzone::truncate_player_punishments'),
]
]);
}

public function truncateShouts(Request $request): \Illuminate\Http\RedirectResponse
{
Log::alert('TRUNCATE_SHOUTS', [
'causer' => $request->user()->username,
]);

Cache::put('dangerzone::truncate_shouts', now(), 3600 * 24);
TruncateShoutsJob::dispatch();

return redirect()->back()
Expand All @@ -42,6 +55,8 @@ public function truncateConsolelogs(Request $request): \Illuminate\Http\Redirect
Log::alert('TRUNCATE_CONSOLELOGS', [
'causer' => $request->user()->username,
]);

Cache::put('dangerzone::truncate_consolelogs', now(), 3600 * 24);
TruncateServerConsolelogsJob::dispatch();

return redirect()->back()
Expand All @@ -53,6 +68,8 @@ public function truncateChatlogs(Request $request): \Illuminate\Http\RedirectRes
Log::alert('TRUNCATE_CHATLOGS', [
'causer' => $request->user()->username,
]);

Cache::put('dangerzone::truncate_chatlogs', now(), 3600 * 24);
TruncateServerChatlogsJob::dispatch();

return redirect()->back()
Expand All @@ -64,6 +81,8 @@ public function truncatePlayerIntelData(Request $request): \Illuminate\Http\Redi
Log::alert('TRUNCATE_PLAYER_INTEL', [
'causer' => $request->user()->username,
]);

Cache::put('dangerzone::truncate_player_intel_data', now(), 3600 * 24);
TruncatePlayerIntelJob::dispatch();

return redirect()->back()
Expand All @@ -75,9 +94,24 @@ public function truncateServerIntelData(Request $request): \Illuminate\Http\Redi
Log::alert('TRUNCATE_SERVER_INTEL', [
'causer' => $request->user()->username,
]);

Cache::put('dangerzone::truncate_server_intel_data', now(), 3600 * 24);
TruncateServerIntelJob::dispatch();

return redirect()->back()
->with(['toast' => ['type' => 'success', 'milliseconds' => 10000, 'title' => __('Queued Successfully! Server Analytics data will be deleted shortly. It may take upto 1 minute to complete.')]]);
}

public function truncatePlayerPunishments(Request $request): \Illuminate\Http\RedirectResponse
{
Log::alert('TRUNCATE_PLAYER_PUNISHMENTS', [
'causer' => $request->user()->username,
]);

Cache::put('dangerzone::truncate_player_punishments', now(), 3600 * 24);
TruncatePlayerPunishmentJob::dispatch();

return redirect()->back()
->with(['toast' => ['type' => 'success', 'milliseconds' => 10000, 'title' => __('Queued Successfully! Player Punishments data will be deleted shortly. It may take upto few minute to complete.')]]);
}
}
5 changes: 5 additions & 0 deletions app/Jobs/TruncatePlayerIntelJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Cache;

class TruncatePlayerIntelJob implements ShouldQueue
{
Expand All @@ -34,6 +35,8 @@ public function __construct()
*/
public function handle(): void
{
Cache::put('dangerzone::truncate_player_intel_data', now(), 3600 * 24);

DB::transaction(function () {
// Delete player intel.
MinecraftPlayerDeath::query()->delete();
Expand All @@ -45,5 +48,7 @@ public function handle(): void
MinecraftPlayer::query()->delete();
Player::query()->delete();
}, 3);

Cache::forget('dangerzone::truncate_player_intel_data');
}
}
37 changes: 37 additions & 0 deletions app/Jobs/TruncatePlayerPunishmentJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Jobs;

use App\Models\PlayerPunishment;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Cache;

class TruncatePlayerPunishmentJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*/
public function __construct()
{
//
}

/**
* Execute the job.
*/
public function handle(): void
{
Cache::put('dangerzone::truncate_player_punishments', now(), 3600 * 24);

PlayerPunishment::query()->delete();

Cache::forget('dangerzone::truncate_player_punishments');
}
}
5 changes: 5 additions & 0 deletions app/Jobs/TruncateServerChatlogsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Cache;

class TruncateServerChatlogsJob implements ShouldQueue
{
Expand All @@ -26,6 +27,10 @@ public function __construct()
*/
public function handle(): void
{
Cache::put('dangerzone::truncate_chatlogs', now(), 3600 * 24);

ServerChatlog::truncate();

Cache::forget('dangerzone::truncate_chatlogs');
}
}
5 changes: 5 additions & 0 deletions app/Jobs/TruncateServerConsolelogsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Cache;

class TruncateServerConsolelogsJob implements ShouldQueue
{
Expand All @@ -26,6 +27,10 @@ public function __construct()
*/
public function handle(): void
{
Cache::put('dangerzone::truncate_consolelogs', now(), 3600 * 24);

ServerConsolelog::truncate();

Cache::forget('dangerzone::truncate_consolelogs');
}
}
5 changes: 5 additions & 0 deletions app/Jobs/TruncateServerIntelJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Cache;

class TruncateServerIntelJob implements ShouldQueue
{
Expand All @@ -29,11 +30,15 @@ public function __construct()
*/
public function handle(): void
{
Cache::put('dangerzone::truncate_server_intel_data', now(), 3600 * 24);

DB::transaction(function () {
// Delete server intel.
MinecraftWorldLiveInfo::query()->delete();
MinecraftServerWorld::query()->delete();
MinecraftServerLiveInfo::query()->delete();
}, 3);

Cache::forget('dangerzone::truncate_server_intel_data');
}
}
5 changes: 5 additions & 0 deletions app/Jobs/TruncateShoutsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Cache;

class TruncateShoutsJob implements ShouldQueue
{
Expand All @@ -26,6 +27,10 @@ public function __construct()
*/
public function handle(): void
{
Cache::put('dangerzone::truncate_shouts', now(), 3600 * 24);

Shout::truncate();

Cache::forget('dangerzone::truncate_shouts');
}
}
10 changes: 9 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\Providers;

use App\Models\User;
use Illuminate\Queue\Events\JobProcessed;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Queue;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\ServiceProvider;
use Laravel\Pulse\Facades\Pulse;

Expand All @@ -28,7 +31,7 @@ public function boot()
{
//
Pulse::users(function ($ids) {
return User::findMany($ids)->map(fn ($user) => [
return User::findMany($ids)->map(fn($user) => [
'id' => $user->id,
'name' => $user->name,
'extra' => $user->email,
Expand All @@ -46,5 +49,10 @@ public function boot()
return $value;
});
});

// Queue Status
Queue::after(function (JobProcessed $event) {
Cache::set('queue_last_processed', now());
});
}
}
6 changes: 5 additions & 1 deletion resources/default/js/Pages/Admin/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import PlayersPerServerMetricBox from '@/Shared/PlayersPerServerMetricBox.vue';
import PlayersPerCountryMetricBox from '@/Shared/PlayersPerCountryMetricBox.vue';
import NetworkTrendsMetricBox from '@/Shared/NetworkTrendsMetricBox.vue';
import { useAuthorizable } from '@/Composables/useAuthorizable';
import { useHelpers } from '@/Composables/useHelpers';
import PlayersJoinAddressMetricBox from '@/Shared/PlayersJoinAddressMetricBox.vue';
import PlayersMinecraftVersionMetricBox from '@/Shared/PlayersMinecraftVersionMetricBox.vue';
const {can} = useAuthorizable();
const {formatTimeAgoToNow} = useHelpers();
defineProps({
kpiTotalUsers: Number,
Expand All @@ -39,6 +41,8 @@ defineProps({
kpiPostCreatedForInterval: Number,
kpiTotalPostsPercent: Number,
kpiTotalComments: Number,
queueLastProcessed: String,
});
</script>

Expand Down Expand Up @@ -122,7 +126,7 @@ defineProps({
change-desc="in last 7 days"
:icon="FireIcon"
icon-class="text-red-500 bg-red-100 dark:bg-red-500 dark:text-white"
description="Jobs failed to run."
:description="`Last Run: ${queueLastProcessed ? formatTimeAgoToNow(queueLastProcessed) : __('not yet')}`"
/>
</div>

Expand Down
Loading

0 comments on commit 2f994d9

Please sign in to comment.