@@ -36,6 +36,7 @@ type Config struct {
3636 AWS * S3Config
3737 Local * LocalConfig
3838 PostgreSQL * PostgreSQLConfig
39+ LoadDays int // New field to specify the number of days to load
3940}
4041
4142// S3Config holds AWS S3 configuration
@@ -352,6 +353,14 @@ func loadConfigFromEnv() (Config, error) {
352353 }
353354 }
354355
356+ // LoadDays configuration
357+ loadDaysStr := os .Getenv ("LOAD_DAYS" )
358+ loadDays , err := strconv .Atoi (loadDaysStr )
359+ if err != nil || loadDays <= 0 {
360+ loadDays = 7 // Default to 7 days if not set or invalid
361+ }
362+ cfg .LoadDays = loadDays
363+
355364 return cfg , nil
356365}
357366
@@ -629,13 +638,17 @@ func loadExistingS3Data(service *Service) error {
629638 }
630639
631640 bucket := service .Config .AWS .Bucket
641+ loadDays := service .Config .LoadDays
642+
643+ // Calculate the cutoff date
644+ cutoffDate := time .Now ().AddDate (0 , 0 , - loadDays )
632645
633646 // List all .pb objects in the bucket
634647 listInput := & s3.ListObjectsV2Input {
635648 Bucket : aws .String (bucket ),
636649 }
637650
638- log .Printf ("Listing all .pb files in S3 bucket: %s" , bucket )
651+ log .Printf ("Listing all .pb files in S3 bucket: %s for the last %d days " , bucket , loadDays )
639652
640653 var continuationToken * string = nil
641654 for {
@@ -654,6 +667,11 @@ func loadExistingS3Data(service *Service) error {
654667 continue // Skip non-.pb files
655668 }
656669
670+ // Check if the object is within the loadDays range
671+ if object .LastModified .Before (cutoffDate ) {
672+ continue
673+ }
674+
657675 log .Printf ("Processing S3 object: %s" , key )
658676
659677 // Download the .pb file
0 commit comments