Skip to content

Commit 7a2c0b6

Browse files
authored
Merge pull request #15 from nullable-eth/fix-ephemeral-container
bug: fix ephemeral container state when DATA_DIR is not set
2 parents aad3a61 + 61e3472 commit 7a2c0b6

File tree

3 files changed

+107
-77
lines changed

3 files changed

+107
-77
lines changed

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func Load() *Config {
7777
VerboseLogging: getBoolEnvWithDefault("VERBOSE_LOGGING", false),
7878

7979
// Storage configuration
80-
DataDir: getEnvWithDefault("DATA_DIR", "/data"),
80+
DataDir: os.Getenv("DATA_DIR"), // No default - ephemeral if not set
8181

8282
// Force update configuration
8383
ForceUpdate: getBoolEnvWithDefault("FORCE_UPDATE", false),

internal/media/processor.go

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ type Processor struct {
5050

5151
// NewProcessor creates a new generic media processor
5252
func NewProcessor(cfg *config.Config, plexClient *plex.Client, tmdbClient *tmdb.Client, radarrClient *radarr.Client, sonarrClient *sonarr.Client) (*Processor, error) {
53-
// Initialize persistent storage
54-
stor, err := storage.NewStorage(cfg.DataDir)
55-
if err != nil {
56-
return nil, fmt.Errorf("failed to initialize storage: %w", err)
53+
// Initialize persistent storage only if DATA_DIR is set
54+
var stor *storage.Storage
55+
if cfg.DataDir != "" {
56+
var err error
57+
stor, err = storage.NewStorage(cfg.DataDir)
58+
if err != nil {
59+
return nil, fmt.Errorf("failed to initialize storage: %w", err)
60+
}
5761
}
5862

5963
processor := &Processor{
@@ -77,9 +81,13 @@ func NewProcessor(cfg *config.Config, plexClient *plex.Client, tmdbClient *tmdb.
7781
}
7882

7983
// Log storage initialization
80-
count := stor.Count()
81-
if count > 0 {
82-
fmt.Printf("📁 Loaded %d previously processed items from storage\n", count)
84+
if stor != nil {
85+
count := stor.Count()
86+
if count > 0 {
87+
fmt.Printf("📁 Loaded %d previously processed items from storage\n", count)
88+
}
89+
} else {
90+
fmt.Printf("🔄 Running in ephemeral mode - no persistent storage (set DATA_DIR to enable)\n")
8391
}
8492

8593
return processor, nil
@@ -156,11 +164,16 @@ func (p *Processor) ProcessAllItems(libraryID string, libraryName string, mediaT
156164
lastProgressReport = progress
157165
}
158166
}
159-
processed, exists := p.storage.Get(item.GetRatingKey())
160-
if exists && processed.KeywordsSynced && processed.UpdateField == p.config.UpdateField && !p.config.ForceUpdate {
161-
skippedItems++
162-
skippedAlreadyExist++
163-
continue
167+
// Check if already processed (only if storage is enabled)
168+
var exists bool
169+
if p.storage != nil {
170+
processed, storageExists := p.storage.Get(item.GetRatingKey())
171+
if storageExists && processed.KeywordsSynced && processed.UpdateField == p.config.UpdateField && !p.config.ForceUpdate {
172+
skippedItems++
173+
skippedAlreadyExist++
174+
continue
175+
}
176+
exists = storageExists
164177
}
165178

166179
// Silently check if we need to process this item
@@ -344,17 +357,20 @@ func (p *Processor) ProcessAllItems(libraryID string, libraryName string, mediaT
344357
}
345358
}
346359

347-
processedItem := &storage.ProcessedItem{
348-
RatingKey: item.GetRatingKey(),
349-
Title: item.GetTitle(),
350-
TMDbID: tmdbID,
351-
LastProcessed: time.Now(),
352-
KeywordsSynced: true,
353-
UpdateField: p.config.UpdateField,
354-
}
360+
// Save processed item (only if storage is enabled)
361+
if p.storage != nil {
362+
processedItem := &storage.ProcessedItem{
363+
RatingKey: item.GetRatingKey(),
364+
Title: item.GetTitle(),
365+
TMDbID: tmdbID,
366+
LastProcessed: time.Now(),
367+
KeywordsSynced: true,
368+
UpdateField: p.config.UpdateField,
369+
}
355370

356-
if err := p.storage.Set(processedItem); err != nil {
357-
fmt.Printf("⚠️ Warning: Failed to save processed item to storage: %v\n", err)
371+
if err := p.storage.Set(processedItem); err != nil {
372+
fmt.Printf("⚠️ Warning: Failed to save processed item to storage: %v\n", err)
373+
}
358374
}
359375

360376
if exists {

0 commit comments

Comments
 (0)