where('status', Status::Connected) ->whereNotNull('token_expires_at') ->where(function (Builder $query) { $query->where(function (Builder $extension) { $extension->whereIn('platform', Platform::accessTokenExtendingPlatformValues()) ->where('token_expires_at', '<=', now()->addDay()); })->orWhere(function (Builder $rotating) { $rotating->whereNotIn('platform', Platform::accessTokenExtendingPlatformValues()) ->where('token_expires_at', '<=', now()->addMinutes(30)); }); }) ->chunk(50, function ($accounts) use (&$count) { foreach ($accounts as $account) { RefreshSocialToken::dispatch($account); $count++; } }); $this->info("Dispatched {$count} token refresh jobs."); } }