From 76d9d41ed8155f277dbf7e6ad796192bb4b4f5fe Mon Sep 17 00:00:00 2001 From: Alex Kaminskii Date: Mon, 16 May 2022 15:31:37 +0200 Subject: [PATCH] refactor(backend/storage): pass FileSplitSize as env var --- backend/Dockerfile | 1 + backend/Dockerfile.bundle | 1 + backend/internal/config/storage/config.go | 36 +++++++++++------------ backend/internal/storage/storage.go | 4 +-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 032093011..3815b6c37 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -47,6 +47,7 @@ ENV TZ=UTC \ CACHE_ASSETS=true \ ASSETS_SIZE_LIMIT=6291456 \ FS_CLEAN_HRS=72 \ + FILE_SPLIT_SIZE=300000 \ LOG_QUEUE_STATS_INTERVAL_SEC=60 diff --git a/backend/Dockerfile.bundle b/backend/Dockerfile.bundle index 100b646c8..407a7b9d8 100644 --- a/backend/Dockerfile.bundle +++ b/backend/Dockerfile.bundle @@ -46,6 +46,7 @@ ENV TZ=UTC \ CACHE_ASSETS=true \ ASSETS_SIZE_LIMIT=6291456 \ FS_CLEAN_HRS=12 \ + FILE_SPLIT_SIZE=300000 \ LOG_QUEUE_STATS_INTERVAL_SEC=60 RUN mkdir $FS_DIR diff --git a/backend/internal/config/storage/config.go b/backend/internal/config/storage/config.go index 305c293c9..28326bd78 100644 --- a/backend/internal/config/storage/config.go +++ b/backend/internal/config/storage/config.go @@ -6,27 +6,27 @@ import ( ) type Config struct { - S3Region string - S3Bucket string - FSDir string - FSCleanHRS int - SessionFileSplitSize int - RetryTimeout time.Duration - GroupStorage string - TopicTrigger string - DeleteTimeout time.Duration + S3Region string + S3Bucket string + FSDir string + FSCleanHRS int + FileSplitSize int + RetryTimeout time.Duration + GroupStorage string + TopicTrigger string + DeleteTimeout time.Duration } func New() *Config { return &Config{ - S3Region: env.String("AWS_REGION_WEB"), - S3Bucket: env.String("S3_BUCKET_WEB"), - FSDir: env.String("FS_DIR"), - FSCleanHRS: env.Int("FS_CLEAN_HRS"), - SessionFileSplitSize: 200000, // ~200 kB - RetryTimeout: 2 * time.Minute, - GroupStorage: env.String("GROUP_STORAGE"), - TopicTrigger: env.String("TOPIC_TRIGGER"), - DeleteTimeout: 48 * time.Hour, + S3Region: env.String("AWS_REGION_WEB"), + S3Bucket: env.String("S3_BUCKET_WEB"), + FSDir: env.String("FS_DIR"), + FSCleanHRS: env.Int("FS_CLEAN_HRS"), + FileSplitSize: env.Int("FILE_SPLIT_SIZE"), + RetryTimeout: 2 * time.Minute, + GroupStorage: env.String("GROUP_STORAGE"), + TopicTrigger: env.String("TOPIC_TRIGGER"), + DeleteTimeout: 48 * time.Hour, } } diff --git a/backend/internal/storage/storage.go b/backend/internal/storage/storage.go index 0051fd5ea..88bb7ad5f 100644 --- a/backend/internal/storage/storage.go +++ b/backend/internal/storage/storage.go @@ -40,7 +40,7 @@ func (s *Storage) UploadKey(key string, retryCount int) { } defer file.Close() - startBytes := make([]byte, s.cfg.SessionFileSplitSize) + startBytes := make([]byte, s.cfg.FileSplitSize) nRead, err := file.Read(startBytes) if err != nil { log.Printf("File read error: %f", err) @@ -50,7 +50,7 @@ func (s *Storage) UploadKey(key string, retryCount int) { if err := s.s3.Upload(s.gzipFile(startReader), key, "application/octet-stream", true); err != nil { log.Fatalf("Storage: start upload failed. %v\n", err) } - if nRead == s.cfg.SessionFileSplitSize { + if nRead == s.cfg.FileSplitSize { if err := s.s3.Upload(s.gzipFile(file), key+"e", "application/octet-stream", true); err != nil { log.Fatalf("Storage: end upload failed. %v\n", err) }