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;
foreach ($users as $user) {
$retries = 0;
while ($retries <= 3) {
try {
$response = Http::withToken($token)
->retry(2, 2000)
->get('https://api.approagency.ir/api/admin/users', [
'mobile' => $user->mobile,
'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()) {
$data = $response->json('data.0');
if ($data) {
@@ -56,12 +67,19 @@ public function handle()
$this->warn(" skip: {$user->mobile} (HTTP {$response->status()})");
$failed++;
}
break;
} catch (\Exception $e) {
$retries++;
if ($retries > 3) {
$this->error(" failed: {$user->mobile}{$e->getMessage()}");
$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}");