fix(seeder): tolerate remote image download timeouts
This commit is contained in:
@@ -110,15 +110,23 @@ class AssetSeeder extends Seeder
|
|||||||
// Download 2 foto berbeda untuk tiap aset dari pool.
|
// Download 2 foto berbeda untuk tiap aset dari pool.
|
||||||
$pics = collect($imagePool)->shuffle()->take(2);
|
$pics = collect($imagePool)->shuffle()->take(2);
|
||||||
foreach ($pics as $idx => $url) {
|
foreach ($pics as $idx => $url) {
|
||||||
$response = Http::get($url);
|
try {
|
||||||
if ($response->ok()) {
|
$response = Http::retry(3, 1000)
|
||||||
$path = "assets/{$asset->id}/photo-{$idx}.jpg";
|
->connectTimeout(10)
|
||||||
Storage::disk('public')->put($path, $response->body());
|
->timeout(20)
|
||||||
AssetPhoto::create([
|
->get($url);
|
||||||
'asset_id' => $asset->id,
|
if ($response->ok()) {
|
||||||
'path' => $path,
|
$path = "assets/{$asset->id}/photo-{$idx}.jpg";
|
||||||
'is_primary' => $idx === 0 && $asset->photos()->count() === 0,
|
Storage::disk('public')->put($path, $response->body());
|
||||||
]);
|
AssetPhoto::create([
|
||||||
|
'asset_id' => $asset->id,
|
||||||
|
'path' => $path,
|
||||||
|
'is_primary' => $idx === 0 && $asset->photos()->count() === 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
// Jika download gagal (timeout/SSL/diblok), seeder tetap lanjut tanpa foto.
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,15 +169,22 @@ class AssetSeeder extends Seeder
|
|||||||
|
|
||||||
// Gunakan foto generik untuk consumable
|
// Gunakan foto generik untuk consumable
|
||||||
$url = 'https://images.unsplash.com/photo-1582719478250-c89cae4dc85b?auto=format&fit=crop&w=800&q=80';
|
$url = 'https://images.unsplash.com/photo-1582719478250-c89cae4dc85b?auto=format&fit=crop&w=800&q=80';
|
||||||
$response = Http::get($url);
|
try {
|
||||||
if ($response->ok()) {
|
$response = Http::retry(3, 1000)
|
||||||
$path = "assets/{$asset->id}/photo-consumable.jpg";
|
->connectTimeout(10)
|
||||||
Storage::disk('public')->put($path, $response->body());
|
->timeout(20)
|
||||||
AssetPhoto::create([
|
->get($url);
|
||||||
'asset_id' => $asset->id,
|
if ($response->ok()) {
|
||||||
'path' => $path,
|
$path = "assets/{$asset->id}/photo-consumable.jpg";
|
||||||
'is_primary' => true,
|
Storage::disk('public')->put($path, $response->body());
|
||||||
]);
|
AssetPhoto::create([
|
||||||
|
'asset_id' => $asset->id,
|
||||||
|
'path' => $path,
|
||||||
|
'is_primary' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user