New returns a new Cron instance.
(config Config)
| 27 | |
| 28 | // New returns a new Cron instance. |
| 29 | func New(config Config) *Cron { |
| 30 | c := &Cron{ |
| 31 | parser: config.Parser, |
| 32 | lock: sync.NewCond(&sync.Mutex{}), |
| 33 | jobDescriptors: jobDescriptors{}, |
| 34 | globalMiddleware: config.GlobalOptions, |
| 35 | location: config.Location, |
| 36 | nextID: 1, |
| 37 | } |
| 38 | if config.Parser == nil { |
| 39 | if config.EnableSeconds { |
| 40 | c.parser = cron.NewParser(cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor) |
| 41 | } else { |
| 42 | c.parser = cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor) |
| 43 | } |
| 44 | } |
| 45 | if config.Location == nil { |
| 46 | c.location = time.Local |
| 47 | } |
| 48 | return c |
| 49 | } |
| 50 | |
| 51 | // Add adds a new job to the cron scheduler.A list of middleware can be supplied. |
| 52 | // Note the error returned by the runner will be discarded. It is the user's |
no outgoing calls