whereNotNull('expires_at') ->where('expires_at', '>', now()) ->where('expires_at', '<=', now()->addDay()) ->where('tokenable_type', User::class) ->chunkById(100, function ($tokens) { foreach ($tokens as $token) { if (! $token->team_id) { continue; } RateLimiter::attempt( 'api-token-expiring:'.$token->id, $maxAttempts = 0, function () use ($token) { Team::find($token->team_id)?->notify(new ApiTokenExpiringNotification($token)); }, $decaySeconds = 7 * 24 * 3600, ); } }); } }