6
6
import org .springframework .beans .factory .annotation .Value ;
7
7
import org .springframework .boot .CommandLineRunner ;
8
8
import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
9
- import org .springframework .core .io .ClassPathResource ;
10
9
import org .springframework .stereotype .Component ;
11
10
12
- import java .nio .file .Files ;
13
- import java .nio .file .Path ;
14
- import java .nio .file .Paths ;
15
11
import java .time .Duration ;
16
12
17
13
@ Component
@@ -24,50 +20,27 @@ public class ModelDataLoaderCommand implements CommandLineRunner {
24
20
25
21
@ Value ("${spring.models.file:newmodels.json}" )
26
22
private String modelsFile ;
23
+
24
+ @ Value ("${spring.models.timeout:300}" )
25
+ private int loadTimeoutSeconds ;
27
26
28
27
@ Override
29
28
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 );
31
30
32
31
// Dosya yolunu belirle
33
32
String jsonFilePath = args .length > 0 && args [0 ] != null && !args [0 ].isEmpty () ?
34
33
args [0 ] : modelsFile ;
35
34
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
63
36
modelDataLoader .loadModelsFromJson (jsonFilePath )
64
- .timeout (Duration .ofMinutes ( 5 ))
37
+ .timeout (Duration .ofSeconds ( loadTimeoutSeconds ))
65
38
.doOnSuccess (count -> {
66
39
log .info ("AI model yükleme işlemi tamamlandı: {} model yüklendi" , count );
67
40
})
68
41
.doOnError (error -> {
69
42
log .error ("AI model yükleme sırasında hata: {}" , error .getMessage (), error );
70
43
})
71
- .subscribe ();
44
+ .block ( Duration . ofSeconds ( loadTimeoutSeconds + 10 )); // Bloke etme süresi timeout + 10 saniye
72
45
}
73
46
}
0 commit comments