Ver Fonte

feature: #202 Cron seconds support optional. Example in default config. (#223)

James Read há 2 anos atrás
pai
commit
0615a7e353
3 ficheiros alterados com 12 adições e 1 exclusões
  1. 3 0
      config.yaml
  2. 2 0
      internal/config/config.go
  3. 7 1
      internal/oncron/cron.go

+ 3 - 0
config.yaml

@@ -21,6 +21,9 @@ actions:
   shellAfterCompleted: "apprise -t 'Notification: Backup script completed' -b 'The backup script completed with code {{ exitCode}}. The log is: \n {{ stdout }} '"
   maxConcurrent: 1
   icon: backup
+  execOnCron: # https://docs.olivetin.app/exec-cron.html
+    - "@monthly"     # Once per month
+    - "0 12 25 12 *" # And on Christmas day!
 
   # This will send 1 ping (-c 1)
   # Docs: https://docs.olivetin.app/action-ping.html

+ 2 - 0
internal/config/config.go

@@ -88,6 +88,7 @@ type Config struct {
 	DefaultPermissions              PermissionsList
 	AccessControlLists              []AccessControlList
 	WebUIDir                        string
+	CronSupportForSeconds           bool
 }
 
 // DefaultConfig gets a new Config structure with sensible default values.
@@ -110,6 +111,7 @@ func DefaultConfig() *Config {
 	config.AuthJwtClaimUsername = "name"
 	config.AuthJwtClaimUserGroup = "group"
 	config.WebUIDir = "./webui"
+	config.CronSupportForSeconds = false
 
 	return &config
 }

+ 7 - 1
internal/oncron/cron.go

@@ -9,7 +9,13 @@ import (
 )
 
 func Schedule(cfg *config.Config, ex *executor.Executor) {
-	scheduler := cron.New(cron.WithSeconds())
+	var scheduler *cron.Cron
+
+	if cfg.CronSupportForSeconds {
+		scheduler = cron.New(cron.WithSeconds())
+	} else {
+		scheduler = cron.New()
+	}
 
 	for _, action := range cfg.Actions {
 		for _, cronline := range action.ExecOnCron {