package configuration import ( "os" "path/filepath" "github.com/pelletier/go-toml/v2" "go.uber.org/zap" ) const ( SNAPZ_CONFIG_ROOT = "/etc/snapz" SNAPZ_JOBS_FILE = "jobs.toml" SNAPZ_DATASET_DIRECTORY = "datasets.toml" ) /* [[job]] name = "example" description = "example job" cron = "* /1 * * * *" recursive = true */ type JobConfig struct { Name string `toml:"name"` Description string `toml:"description"` Cron string `toml:"cron"` Dataset string `toml:"dataset"` Recursive bool `toml:"recusrive"` } type JobsConfig struct { Jobs []JobConfig `toml:"job"` } func getConfigPaths(filename string) []string { global_file_path := filepath.Join(SNAPZ_CONFIG_ROOT, filename) return []string{global_file_path} } func GetJobs() ([]JobConfig, error) { job_file_paths := getConfigPaths(SNAPZ_JOBS_FILE) jobs := make([]JobConfig, 0) for _, file := range job_file_paths { data, err := os.ReadFile(file) if err != nil { return nil, err } var jobsConfig JobsConfig err = toml.Unmarshal(data, &jobsConfig) if err != nil { return nil, err } zap.S().Infof("adding %v jobs to queue", len(jobsConfig.Jobs)) jobs = append(jobs, jobsConfig.Jobs...) } return jobs, nil }