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++; } }); // Accounts in the window, not jobs queued: the job is unique per // account, so a dispatch during a backlog is silently discarded. $this->info("{$count} accounts due for a token refresh."); } }