mirror of
https://github.com/ericasch6/scrum-poker-internal.git
synced 2026-10-13 17:32:09 +00:00
feat: added laravel reverb and websocket, also emote throwing added
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Enums\RoomStateChange;
|
||||
use App\Events\RoomStateChanged;
|
||||
use App\Models\Room;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
@@ -13,7 +15,7 @@ class CloseInactiveRooms implements ShouldQueue
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$closedAt = now();
|
||||
$closedAt = now()->toImmutable();
|
||||
$guestCutoff = $closedAt->subDays(config('rooms.guest_retention_days'));
|
||||
$accountCutoff = $closedAt->subDays(config('rooms.account_retention_days'));
|
||||
|
||||
@@ -32,25 +34,40 @@ class CloseInactiveRooms implements ShouldQueue
|
||||
})
|
||||
->select('id')
|
||||
->chunkById(100, function ($rooms) use ($closedAt, $guestCutoff, $accountCutoff): void {
|
||||
Room::query()
|
||||
->whereKey($rooms->pluck('id'))
|
||||
->whereNull('closed_at')
|
||||
->where(function ($query) use ($guestCutoff, $accountCutoff): void {
|
||||
$query
|
||||
->where(function ($query) use ($guestCutoff): void {
|
||||
$query->whereNull('owner_id')
|
||||
->where('last_activity_at', '<=', $guestCutoff);
|
||||
})
|
||||
->orWhere(function ($query) use ($accountCutoff): void {
|
||||
$query->whereNotNull('owner_id')
|
||||
->where('last_activity_at', '<=', $accountCutoff);
|
||||
});
|
||||
})
|
||||
->update([
|
||||
'closed_at' => $closedAt,
|
||||
'state_version' => DB::raw('state_version + 1'),
|
||||
'updated_at' => $closedAt,
|
||||
]);
|
||||
foreach ($rooms->pluck('id') as $roomId) {
|
||||
$stateVersion = DB::transaction(function () use ($roomId, $closedAt, $guestCutoff, $accountCutoff): ?int {
|
||||
$room = Room::query()
|
||||
->lockForUpdate()
|
||||
->find((string) $roomId);
|
||||
|
||||
if ($room === null || $room->isClosed() || $room->last_activity_at === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cutoff = $room->owner_id === null
|
||||
? $guestCutoff
|
||||
: $accountCutoff;
|
||||
|
||||
if ($room->last_activity_at->greaterThan($cutoff)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$room->update([
|
||||
'closed_at' => $closedAt,
|
||||
'state_version' => $room->state_version + 1,
|
||||
]);
|
||||
|
||||
return $room->state_version;
|
||||
});
|
||||
|
||||
if ($stateVersion !== null) {
|
||||
RoomStateChanged::dispatch(
|
||||
(string) $roomId,
|
||||
$stateVersion,
|
||||
RoomStateChange::RoomClosed,
|
||||
);
|
||||
}
|
||||
}
|
||||
}, 'id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user