Schedule adds a Job to the Cron to be run on the given schedule. The job is wrapped with the configured Chain.
(schedule Schedule, cmd Job)
| 156 | // Schedule adds a Job to the Cron to be run on the given schedule. |
| 157 | // The job is wrapped with the configured Chain. |
| 158 | func (c *Cron) Schedule(schedule Schedule, cmd Job) EntryID { |
| 159 | c.runningMu.Lock() |
| 160 | defer c.runningMu.Unlock() |
| 161 | c.nextID++ |
| 162 | entry := &Entry{ |
| 163 | ID: c.nextID, |
| 164 | Schedule: schedule, |
| 165 | WrappedJob: c.chain.Then(cmd), |
| 166 | Job: cmd, |
| 167 | } |
| 168 | if !c.running { |
| 169 | c.entries = append(c.entries, entry) |
| 170 | } else { |
| 171 | c.add <- entry |
| 172 | } |
| 173 | return entry.ID |
| 174 | } |
| 175 | |
| 176 | // Entries returns a snapshot of the cron entries. |
| 177 | func (c *Cron) Entries() []Entry { |