1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package scheduler
- import (
- "encoding/json"
- "io/ioutil"
- )
- //Load a list of jobs from file
- func loadJobsFromFile(cronfile string) ([]*Job, error) {
- //Try to read the cronfile
- filecontent, err := ioutil.ReadFile(cronfile)
- if err != nil {
- return []*Job{}, err
- }
- //Phrase the cronfile
- prevousJobs := []*Job{}
- err = json.Unmarshal(filecontent, &prevousJobs)
- if err != nil {
- return []*Job{}, err
- }
- return prevousJobs, nil
- }
- //save the changes in job list to file
- func (a *Scheduler) saveJobsToCronFile() error {
- js, err := json.Marshal(a.jobs)
- if err != nil {
- return err
- }
- return ioutil.WriteFile(a.options.CronFile, js, 0775)
- }
- func (a *Scheduler) cronlog(message string) {
- a.options.Logger.PrintAndLog("Scheduler", message, nil)
- }
- func (a *Scheduler) cronlogError(message string, err error) {
- a.options.Logger.PrintAndLog("Scheduler", message, err)
- }
|