Register adds a job. It must be called before Start; calling it after Start returns an error.
(job CronJob)
| 87 | // Register adds a job. It must be called before Start; calling it |
| 88 | // after Start returns an error. |
| 89 | func (c *Cron) Register(job CronJob) error { |
| 90 | if !job.EventType.IsHeartbeat() { |
| 91 | return xerrors.New("event type must be a heartbeat type") |
| 92 | } |
| 93 | if c.started.Load() { |
| 94 | return xerrors.New("cannot register a job after Start has been called") |
| 95 | } |
| 96 | c.jobs = append(c.jobs, job) |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | // Start launches a goroutine per job. Subsequent calls are no-ops. |
| 101 | // On daemon restart a new Cron should be created. |