66import org .springframework .beans .factory .annotation .Value ;
77import org .springframework .boot .CommandLineRunner ;
88import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
9- import org .springframework .core .io .ClassPathResource ;
109import org .springframework .stereotype .Component ;
1110
12- import java .nio .file .Files ;
13- import java .nio .file .Path ;
14- import java .nio .file .Paths ;
1511import java .time .Duration ;
1612
1713@ Component
@@ -24,50 +20,27 @@ public class ModelDataLoaderCommand implements CommandLineRunner {
2420
2521 @ Value ("${spring.models.file:newmodels.json}" )
2622 private String modelsFile ;
23+
24+ @ Value ("${spring.models.timeout:300}" )
25+ private int loadTimeoutSeconds ;
2726
2827 @ Override
2928 public void run (String ... args ) {
30- log .info ("AI modelleri yükleme işlemi başlıyor..." );
29+ log .info ("Başlangıçta model yükleme etkin. '{}' dosyasından modeller yükleniyor" , modelsFile );
3130
3231 // Dosya yolunu belirle
3332 String jsonFilePath = args .length > 0 && args [0 ] != null && !args [0 ].isEmpty () ?
3433 args [0 ] : modelsFile ;
3534
36- // Önce classpath resource olarak kontrol et
37- org .springframework .core .io .Resource resource =
38- new ClassPathResource (jsonFilePath .replace ("classpath:" , "" ));
39-
40- if (resource .exists ()) {
41- log .info ("'{}' classpath kaynağından modeller yükleniyor" , jsonFilePath );
42- modelDataLoader .loadModelsFromJson (jsonFilePath )
43- .timeout (Duration .ofMinutes (5 ))
44- .doOnSuccess (count -> {
45- log .info ("AI model yükleme işlemi tamamlandı: {} model yüklendi" , count );
46- })
47- .doOnError (error -> {
48- log .error ("AI model yükleme sırasında hata: {}" , error .getMessage (), error );
49- })
50- .subscribe ();
51- return ;
52- }
53-
54- // Resource olarak bulunamazsa, dosya sistemi olarak kontrol et
55- Path path = Paths .get (jsonFilePath );
56- if (!Files .exists (path )) {
57- log .error ("Model dosyası bulunamadı: {}" , path .toAbsolutePath ());
58- return ;
59- }
60-
61- log .info ("'{}' dosyasından modeller yükleniyor" , jsonFilePath );
62-
35+ // Modelleri yükle ve işlem tamamlanana kadar bekle
6336 modelDataLoader .loadModelsFromJson (jsonFilePath )
64- .timeout (Duration .ofMinutes ( 5 ))
37+ .timeout (Duration .ofSeconds ( loadTimeoutSeconds ))
6538 .doOnSuccess (count -> {
6639 log .info ("AI model yükleme işlemi tamamlandı: {} model yüklendi" , count );
6740 })
6841 .doOnError (error -> {
6942 log .error ("AI model yükleme sırasında hata: {}" , error .getMessage (), error );
7043 })
71- .subscribe ();
44+ .block ( Duration . ofSeconds ( loadTimeoutSeconds + 10 )); // Bloke etme süresi timeout + 10 saniye
7245 }
7346}
0 commit comments