mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
|
||||
Package workers contains auto indexing & importing workers.
|
||||
Package auto contains index & import background workers.
|
||||
|
||||
Copyright (c) 2018 - 2021 Michael Mayer <hello@photoprism.org>
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ func ShouldIndex() {
|
||||
autoIndex = time.Now()
|
||||
}
|
||||
|
||||
// mustIndex tests if auto indexing must be started.
|
||||
// mustIndex tests if the index must be updated.
|
||||
func mustIndex(delay time.Duration) bool {
|
||||
if delay.Seconds() <= 0 {
|
||||
return false
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
var StopCommand = cli.Command{
|
||||
Name: "stop",
|
||||
Aliases: []string{"down"},
|
||||
Usage: "Stops the web server when running in daemon mode",
|
||||
Usage: "Stops the web server in daemon mode",
|
||||
Action: stopAction,
|
||||
}
|
||||
|
||||
|
||||
@@ -71,8 +71,9 @@ type Config struct {
|
||||
func init() {
|
||||
TotalMem = memory.TotalMemory()
|
||||
|
||||
// Disable features with high memory requirements unless PHOTOPRISM_UNSAFE is set.
|
||||
// Check available memory if not running in unsafe mode.
|
||||
if os.Getenv("PHOTOPRISM_UNSAFE") == "" {
|
||||
// Disable features with high memory requirements?
|
||||
LowMem = TotalMem < MinMem
|
||||
}
|
||||
|
||||
@@ -475,31 +476,35 @@ func (c *Config) Workers() int {
|
||||
return 1
|
||||
}
|
||||
|
||||
// WakeupInterval returns the background worker wakeup interval duration.
|
||||
// WakeupInterval returns the metadata, share & sync background worker wakeup interval duration (1 - 604800 seconds).
|
||||
func (c *Config) WakeupInterval() time.Duration {
|
||||
if c.options.WakeupInterval <= 0 || c.options.WakeupInterval > 86400 {
|
||||
if c.options.Unsafe && c.options.WakeupInterval < 0 {
|
||||
// Background worker can be disabled in unsafe mode.
|
||||
return time.Duration(0)
|
||||
} else if c.options.WakeupInterval <= 0 || c.options.WakeupInterval > 604800 {
|
||||
// Default if out of range.
|
||||
return time.Duration(DefaultWakeupInterval) * time.Second
|
||||
}
|
||||
|
||||
return time.Duration(c.options.WakeupInterval) * time.Second
|
||||
}
|
||||
|
||||
// AutoIndex returns the auto indexing delay duration.
|
||||
// AutoIndex returns the auto index delay duration.
|
||||
func (c *Config) AutoIndex() time.Duration {
|
||||
if c.options.AutoIndex < 0 {
|
||||
return time.Duration(0)
|
||||
} else if c.options.AutoIndex == 0 || c.options.AutoIndex > 86400 {
|
||||
} else if c.options.AutoIndex == 0 || c.options.AutoIndex > 604800 {
|
||||
return time.Duration(DefaultAutoIndexDelay) * time.Second
|
||||
}
|
||||
|
||||
return time.Duration(c.options.AutoIndex) * time.Second
|
||||
}
|
||||
|
||||
// AutoImport returns the auto importing delay duration.
|
||||
// AutoImport returns the auto import delay duration.
|
||||
func (c *Config) AutoImport() time.Duration {
|
||||
if c.options.AutoImport < 0 || c.ReadOnly() {
|
||||
return time.Duration(0)
|
||||
} else if c.options.AutoImport == 0 || c.options.AutoImport > 86400 {
|
||||
} else if c.options.AutoImport == 0 || c.options.AutoImport > 604800 {
|
||||
return time.Duration(DefaultAutoImportDelay) * time.Second
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ var GlobalFlags = []cli.Flag{
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "pid-filename",
|
||||
Usage: "process id `FILENAME` when running in daemon mode",
|
||||
Usage: "daemon mode process id `FILENAME`",
|
||||
EnvVar: "PHOTOPRISM_PID_FILENAME",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
@@ -36,6 +36,12 @@ var GlobalFlags = []cli.Flag{
|
||||
Hidden: true,
|
||||
Usage: "enable test mode",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "unsafe",
|
||||
Hidden: true,
|
||||
Usage: "enable unsafe mode",
|
||||
EnvVar: "PHOTOPRISM_UNSAFE",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "demo",
|
||||
Hidden: true,
|
||||
@@ -55,7 +61,7 @@ var GlobalFlags = []cli.Flag{
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "admin-password",
|
||||
Usage: "initial admin user `PASSWORD`, minimum 4 characters",
|
||||
Usage: "initial admin `PASSWORD`, minimum 4 characters",
|
||||
EnvVar: "PHOTOPRISM_ADMIN_PASSWORD",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
@@ -132,13 +138,13 @@ var GlobalFlags = []cli.Flag{
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "wakeup-interval",
|
||||
Usage: "background worker wakeup interval in `SECONDS`",
|
||||
Usage: "metadata, share & sync background worker wakeup interval in `SECONDS` (1-604800)",
|
||||
Value: DefaultWakeupInterval,
|
||||
EnvVar: "PHOTOPRISM_WAKEUP_INTERVAL",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "auto-index",
|
||||
Usage: "WebDAV auto indexing safety delay in `SECONDS`, disable with -1",
|
||||
Usage: "WebDAV auto index safety delay in `SECONDS`, disable with -1",
|
||||
Value: DefaultAutoIndexDelay,
|
||||
EnvVar: "PHOTOPRISM_AUTO_INDEX",
|
||||
},
|
||||
@@ -175,7 +181,7 @@ var GlobalFlags = []cli.Flag{
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "disable-ffmpeg",
|
||||
Usage: "disable video transcoding and still image extraction with FFmpeg",
|
||||
Usage: "disable video transcoding and thumbnail extraction with FFmpeg",
|
||||
EnvVar: "PHOTOPRISM_DISABLE_FFMPEG",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
@@ -338,7 +344,7 @@ var GlobalFlags = []cli.Flag{
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "darktable-blacklist",
|
||||
Usage: "file `EXTENSIONS` not to be converted with Darktable",
|
||||
Usage: "RAW file `EXTENSIONS` incompatible with Darktable",
|
||||
Value: "raf,cr3,dng",
|
||||
EnvVar: "PHOTOPRISM_DARKTABLE_BLACKLIST",
|
||||
},
|
||||
@@ -350,7 +356,7 @@ var GlobalFlags = []cli.Flag{
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "rawtherapee-blacklist",
|
||||
Usage: "file `EXTENSIONS` not to be converted with RawTherapee",
|
||||
Usage: "RAW file `EXTENSIONS` incompatible with RawTherapee",
|
||||
Value: "",
|
||||
EnvVar: "PHOTOPRISM_RAWTHERAPEE_BLACKLIST",
|
||||
},
|
||||
@@ -368,7 +374,7 @@ var GlobalFlags = []cli.Flag{
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "ffmpeg-bin",
|
||||
Usage: "FFmpeg `COMMAND` for video transcoding and still image extraction",
|
||||
Usage: "FFmpeg `COMMAND` for video transcoding and thumbnail extraction",
|
||||
Value: "ffmpeg",
|
||||
EnvVar: "PHOTOPRISM_FFMPEG_BIN",
|
||||
},
|
||||
|
||||
@@ -37,6 +37,7 @@ type Options struct {
|
||||
LogLevel string `yaml:"LogLevel" json:"-" flag:"log-level"`
|
||||
LogFilename string `yaml:"LogFilename" json:"-" flag:"log-filename"`
|
||||
Test bool `yaml:"-" json:"Test,omitempty" flag:"test"`
|
||||
Unsafe bool `yaml:"-" json:"-" flag:"unsafe"`
|
||||
Demo bool `yaml:"Demo" json:"-" flag:"demo"`
|
||||
Sponsor bool `yaml:"-" json:"-" flag:"sponsor"`
|
||||
Public bool `yaml:"Public" json:"-" flag:"public"`
|
||||
|
||||
@@ -42,9 +42,17 @@ import (
|
||||
var log = event.Log
|
||||
var stop = make(chan bool, 1)
|
||||
|
||||
// Start runs PhotoPrism background workers every wakeup interval.
|
||||
// Start runs the metadata, share & sync background workers at regular intervals.
|
||||
func Start(conf *config.Config) {
|
||||
ticker := time.NewTicker(conf.WakeupInterval())
|
||||
interval := conf.WakeupInterval()
|
||||
|
||||
// Disabled in safe mode?
|
||||
if interval.Seconds() <= 0 {
|
||||
log.Warnf("config: disabled metadata, share & sync background workers")
|
||||
return
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(interval)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
|
||||
Reference in New Issue
Block a user