Skip to content
Snippets Groups Projects
Select Git revision
  • 56f174e768b25966a3bc1678f6ea659b6913b0b1
  • master default protected
  • 0.5.9
  • 0.5.8
  • 0.5.7
  • 0.5.6
  • 0.5.5
  • 0.5.4
  • 0.5.3
  • 0.5.2
  • 0.5.1
  • 0.5.0
  • 0.4.17
  • 0.4.16
  • 0.4.15
  • 0.4.14
  • 0.4.13
  • 0.4.12
  • 0.4.11
  • 0.4.10
  • 0.4.9
  • 0.4.8
22 results

target-help.mk

Blame
  • scheduler.go 3.56 KiB
    // Copyright 2023 schukai GmbH
    // SPDX-License-Identifier: AGPL-3.0
    
    package jobqueue
    
    import (
    	"encoding/json"
    	"github.com/fsnotify/fsnotify"
    	"strings"
    	"time"
    )
    
    type StopChan chan bool
    
    type Scheduler interface {
    	Schedule(job GenericJob, eventBus *EventBus) error
    	Cancel(id JobID) error
    	CancelAll() error
    	JobExists(id JobID) bool
    
    	GetType() string
    
    	IsAdHoc() bool
    
    	GetPersistence() SchedulerPersistence
    }
    
    type SchedulerPersistence struct {
    	Type       string        `yaml:"type" json:"type" gorm:"column:type"`
    	Interval   time.Duration `yaml:"interval,omitempty" json:"interval,omitempty" gorm:"column:interval"`
    	Spec       string        `yaml:"spec,omitempty" json:"spec,omitempty" gorm:"column:spec"`
    	Delay      time.Duration `yaml:"delay,omitempty" json:"delay,omitempty" gorm:"column:delay"`
    	Event      EventName     `yaml:"event,omitempty" json:"event,omitempty" gorm:"column:event"`
    	Time       *time.Time    `yaml:"time,omitempty" json:"time,omitempty" gorm:"column:time"`
    	Executed   bool          `yaml:"executed,omitempty" json:"executed,omitempty" gorm:"column:executed"`
    	Path       string        `yaml:"path,omitempty" json:"path,omitempty" gorm:"column:path"`
    	EventFlags fsnotify.Op   `yaml:"eventFlags,omitempty" json:"eventFlags,omitempty" gorm:"column:eventFlags"`
    }
    
    type scheduleImportStruct struct {
    	Time       *string `yaml:"time,omitempty" json:"time,omitempty"`
    	Interval   *string `yaml:"interval,omitempty" json:"interval,omitempty"`
    	Delay      *string `yaml:"delay,omitempty" json:"delay,omitempty"`
    	EventFlags *string `yaml:"eventFlags,omitempty" json:"eventFlags,omitempty"`
    
    	Type     string `yaml:"type" json:"type"`
    	Spec     string `yaml:"spec,omitempty" json:"spec,omitempty"`
    	Event    string `yaml:"event,omitempty" json:"event,omitempty"`
    	Executed bool   `yaml:"executed,omitempty" json:"executed,omitempty"`
    	Path     string `yaml:"path,omitempty" json:"path,omitempty"`
    }
    
    func (sp *SchedulerPersistence) parseAndAssignFields(aux scheduleImportStruct) error {
    
    	sp.Type = aux.Type
    	sp.Spec = aux.Spec
    	sp.Event = EventName(aux.Event)
    	sp.Executed = aux.Executed
    	sp.Path = aux.Path
    
    	if aux.Time != nil && *aux.Time != "" {
    		var t time.Time
    		var err error
    		for _, format := range SupportedTimeFormats {
    			t, err = time.Parse(format, *aux.Time)
    			if err == nil {
    				break
    			}
    		}
    		if err != nil {