fix: make sure approved invites are not deleted daily
even though people would have time to use approved invites (24 hrs at least), it would be better to delete them when they expire instead. Signed-off-by: Miguel Nogueira <me@nogueira.codes>
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Jobs;
|
||||
use App\Invitation;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
// General Housekeeping Job: Drop Approved and Completed Invites
|
||||
class InviteLifecycleCleanup implements ShouldQueue
|
||||
@@ -24,11 +25,18 @@ class InviteLifecycleCleanup implements ShouldQueue
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
Invitation::whereIn('status', ['approved', 'completed'])
|
||||
->chunkById(100, function ($invites) {
|
||||
Log::info("Invite lifecycle: processing completed invites.");
|
||||
$deleted = 0;
|
||||
|
||||
Invitation::where('status', '=', 'completed')
|
||||
->chunkById(100, function ($invites) use (&$deleted) {
|
||||
foreach ($invites as $invite) {
|
||||
Log::debug("Deleted invite {$invite->invitation_code} for {$invite->requestor_email}.");
|
||||
$invite->delete();
|
||||
$deleted++;
|
||||
}
|
||||
});
|
||||
|
||||
Log::info("Deleted {$deleted} completed invitations.");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user