use App\DTO\JobResponseDTO;
use App\Enums\ApiName;
use App\Exceptions\ApiKeyNotFoundException;
use App\Exceptions\CategoryNotFoundException;
use App\Models\ApiKey;
use Illuminate\Support\Facades\Log;
class GetJobData implements ShouldQueue
{
// ...
public function handle(): void
{
try {
$apiKey = ApiKey::query()
->where('api_name', ApiName::JOB)
->orderByDesc('request_remaining')
->first();
ApiKeyNotFoundException::validateApiKey($apiKey);
$categories = JobCategory::all();
CategoryNotFoundException::throwIfNotFound($categories);
foreach ($categories as $category) {
$this->fetchAndStoreJobs($apiKey, $category);
}
} catch (ApiKeyNotFoundException|CategoryNotFoundException|\Exception $e) {
Log::error('Error on job fetching', [
'message' => $e->getMessage(),
'line' => $e->getLine(),
'file' => $e->getFile(),
]);
}
}
// ...
}