// scheduleNextRun Compute the instant when this Job should run next
scheduleNextRun Compute the instant when this Job should run next
// scheduleNextRun Compute the instant when this Job should run next
func (s *Scheduler) scheduleNextRun(job *Job) {
	now := s.now()
	lastRun := job.LastRun()
	if !s.jobPresent(job) {
		return
	}
	if job.getStartsImmediately() {
		s.run(job)
		lastRun = now
		job.setStartsImmediately(false)
	}
	if job.neverRan() {
		if !job.startAtTime.IsZero() && job.startAtTime.Before(now) {
			duration := s.durationToNextRun(job.startAtTime, job)
			job.startAtTime = job.startAtTime.Add(duration)
			if job.startAtTime.Before(now) {
				diff := now.Sub(job.startAtTime)
				duration := s.durationToNextRun(job.startAtTime, job)
				count := diff / duration
				if diff%duration != 0 {
					count++
				}
				job.startAtTime = job.startAtTime.Add(duration * count)
			}
		}
		lastRun = now
	}
	if !job.shouldRun() {
		s.RemoveByReference(job)
		return
	}
	durationToNextRun := s.durationToNextRun(lastRun, job)
	job.setNextRun(lastRun.Add(durationToNextRun))
	job.setTimer(time.AfterFunc(durationToNextRun, func() {
		s.run(job)
		s.scheduleNextRun(job)
	}))
}
func ( s * Scheduler ) scheduleNextRun ( job * Job ) { now := s . now ( ) lastRun := job . LastRun ( ) if ! s . jobPresent ( job ) { return } if job . getStartsImmediately ( ) { s . run ( job ) lastRun = now job . setStartsImmediately ( false ) } if job . neverRan ( ) { if ! job . startAtTime . IsZero ( ) && job . startAtTime . Before ( now ) { duration := s . durationToNextRun ( job . startAtTime , job ) job . startAtTime = job . startAtTime . Add ( duration ) if job . startAtTime . Before ( now ) { diff := now . Sub ( job . startAtTime ) duration := s . durationToNextRun ( job . startAtTime , job ) count := diff / duration if diff % duration != 0 { count ++ } job . startAtTime = job . startAtTime . Add ( duration * count ) } } lastRun = now } if ! job . shouldRun ( ) { s . RemoveByReference ( job ) return } durationToNextRun := s . durationToNextRun ( lastRun , job ) job . setNextRun ( lastRun . Add ( durationToNextRun ) ) job . setTimer ( time . AfterFunc ( durationToNextRun , func ( ) { s . run ( job ) s . scheduleNextRun ( job ) } ) ) }
scheduleNextRun Compute the instant when this Job should run next
scheduleNextRun Compute the instant when this Job should run next
// Increment startAtTime to the future