48 lines
1.7 KiB
Java
48 lines
1.7 KiB
Java
package fr.tetelie.crawler;
|
|
|
|
import io.github.cdimascio.dotenv.Dotenv;
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
@SpringBootApplication
|
|
@EnableScheduling
|
|
public class Crawler {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
// 1. Création des instances (Fidèle à ton code)
|
|
new WebScrapper();
|
|
new DatabaseConfig();
|
|
|
|
// 2. Connexion initiale
|
|
boolean isConnected = DatabaseConfig.getInstance().connect();
|
|
if(!isConnected){
|
|
System.err.println("Impossible de démarrer : BDD injoignable.");
|
|
return;
|
|
}
|
|
|
|
// 3. Setup Environnement et Spring
|
|
Dotenv dotenv = Dotenv.configure().ignoreIfMissing().load();
|
|
dotenv.entries().forEach(entry -> System.setProperty(entry.getKey(), entry.getValue()));
|
|
SpringApplication.run(Crawler.class, args);
|
|
|
|
// 4. Ta boucle infinie de 24h
|
|
while (true) {
|
|
System.out.println("--- Début d'un cycle de mise à jour ---");
|
|
|
|
// Les méthodes récupèrent maintenant une connexion fraîche via le pool
|
|
DatabaseConfig.getInstance().updatesAllMissingImages();
|
|
DatabaseConfig.getInstance().updateAllPrices();
|
|
|
|
System.out.println("Cycle terminé. Sommeil de 24 heures...");
|
|
try {
|
|
// 24 heures de pause
|
|
Thread.sleep(24 * 60 * 60 * 1000);
|
|
} catch (InterruptedException e) {
|
|
System.err.println("Le programme a été interrompu.");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |