This commit is contained in:
2026-08-20 18:38:04 +03:30
parent f505180237
commit 3f3b5b1d69
+19 -1
View File
@@ -30,13 +30,24 @@ public function handle()
$failed = 0; $failed = 0;
foreach ($users as $user) { foreach ($users as $user) {
$retries = 0;
while ($retries <= 3) {
try { try {
$response = Http::withToken($token) $response = Http::withToken($token)
->retry(2, 2000)
->get('https://api.approagency.ir/api/admin/users', [ ->get('https://api.approagency.ir/api/admin/users', [
'mobile' => $user->mobile, 'mobile' => $user->mobile,
'per_page' => 1, 'per_page' => 1,
]); ]);
if ($response->status() === 429) {
$retries++;
$wait = $retries * 3;
$this->warn(" rate limited on {$user->mobile}, waiting {$wait}s...");
sleep($wait);
continue;
}
if ($response->successful()) { if ($response->successful()) {
$data = $response->json('data.0'); $data = $response->json('data.0');
if ($data) { if ($data) {
@@ -56,12 +67,19 @@ public function handle()
$this->warn(" skip: {$user->mobile} (HTTP {$response->status()})"); $this->warn(" skip: {$user->mobile} (HTTP {$response->status()})");
$failed++; $failed++;
} }
break;
} catch (\Exception $e) { } catch (\Exception $e) {
$retries++;
if ($retries > 3) {
$this->error(" failed: {$user->mobile}{$e->getMessage()}"); $this->error(" failed: {$user->mobile}{$e->getMessage()}");
$failed++; $failed++;
} else {
sleep($retries * 2);
}
}
} }
usleep(200000); // 200ms delay to avoid rate limits sleep(3); // 3s between requests
} }
$this->info("Done. Synced: {$synced}, Failed: {$failed}"); $this->info("Done. Synced: {$synced}, Failed: {$failed}");