summaryrefslogtreecommitdiff
path: root/main.go
diff options
from:
to:
context:
space:
mode:
authorGravatar SayaAndy <saya.andy@posteo.com> 2026-02-09 06:33:35 +0700
committerGravatar SayaAndy <saya.andy@posteo.com> 2026-02-09 06:33:35 +0700
commitebfe3540c333ae7fa3effb410a20e5764627e307 (patch)
tree543aa1d73463dcd381f732d67b3361dd53a926a0 /main.go
parentda672112ebbc25a3fa9f2cf8e37994a7bd1d0e2f (diff)
downloadthumbnail-generator-ebfe3540c333ae7fa3effb410a20e5764627e307.tar.gz
thumbnail-generator-ebfe3540c333ae7fa3effb410a20e5764627e307.zip
feat: add jpeg converter
fix: explicitly set content type for b2 feat: extend rewrite settings with "never overwrite" feat: move rewrite setting to converter config feat: allow to skip size config
Diffstat (limited to 'main.go')
-rw-r--r--main.go62
1 files changed, 42 insertions, 20 deletions
diff --git a/main.go b/main.go
index 521960e..5735e19 100644
--- a/main.go
+++ b/main.go
@@ -128,26 +128,38 @@ func main() {
}
}
+ select {
+ case <-sigTermChan:
+ generalLogger.Info("exiting due to termination signal")
+ os.Exit(130)
+ default:
+ }
+
processSemaphore := make(chan struct{}, cfg.MaxProcessThreads)
queueSemaphore := make(chan struct{}, cfg.MaxPreProcessThreads)
var wg sync.WaitGroup
wg.Add(fileCount)
+ processTerminating := false
+
for i, file := range files {
queueSemaphore <- struct{}{}
- go func(index int, inputName string) {
- fileLogger := generalLogger.With(slog.String("input_path", inputName), slog.Int("file_index", index))
- threadSigTermChannel := make(chan os.Signal, 1)
- signal.Notify(threadSigTermChannel, os.Interrupt, syscall.SIGTERM)
+ select {
+ case <-sigTermChan:
+ generalLogger.Info("exiting due to termination signal")
+ processTerminating = true
+ default:
+ }
+ go func(index int, inputName string, earlyTerminate bool) {
defer func() { <-queueSemaphore; wg.Done() }()
- select {
- case <-threadSigTermChannel:
- fileLogger.Info("exiting due to termination signal")
+ fileLogger := generalLogger.With(slog.String("input_path", inputName), slog.Int("file_index", index))
+
+ if earlyTerminate {
+ fileLogger.Info("skip processing file (process is terminating)")
return
- default:
}
var inputMetadata *input.MetadataStruct
@@ -185,21 +197,31 @@ func main() {
}
}
- if !cfg.ForceRewrite && !conv.IsMissing(outputName) {
- outputMetadata, err := conv.ReadMetadata(outputName)
- if err != nil {
- convLogger.Warn("fail to read metadata of (supposedly existing) output file", slog.String("error", err.Error()))
+ switch cfg.Converters[j].Output.RewriteOn {
+ case "Never":
+ if !conv.IsMissing(outputName) {
+ convLogger.Info("skip already existing file")
continue
}
- originalInputHash = outputMetadata.HashOriginal
- if inputMetadata.Hash == originalInputHash {
- convLogger.Info("skip already processed file (based on equal hash)", slog.String("input_hash", inputMetadata.Hash))
- cacheMapMutex.Lock()
- cacheMap[id][converterHashes[j]] = struct{}{}
- cacheMapMutex.Unlock()
- continue
+ case "UnequalHashInCache":
+ if !conv.IsMissing(outputName) {
+ outputMetadata, err := conv.ReadMetadata(outputName)
+ if err != nil {
+ convLogger.Warn("fail to read metadata of (supposedly existing) output file", slog.String("error", err.Error()))
+ continue
+ }
+ originalInputHash = outputMetadata.HashOriginal
+ if inputMetadata.Hash == originalInputHash {
+ convLogger.Info("skip already processed file (based on equal hash)", slog.String("input_hash", inputMetadata.Hash))
+ cacheMapMutex.Lock()
+ cacheMap[id][converterHashes[j]] = struct{}{}
+ cacheMapMutex.Unlock()
+ continue
+ }
}
+ case "Always":
}
+
convertersToLaunch = append(convertersToLaunch, j)
}
@@ -239,7 +261,7 @@ func main() {
cacheMap[id][converterHashes[convIndex]] = struct{}{}
cacheMapMutex.Unlock()
}
- }(i, file)
+ }(i, file, processTerminating)
}
wg.Wait()