// Go through every possible job and find the next one.
// TODO: Some form of indexing would be way better
Go through every possible job and find the next one.
TODO: Some form of indexing would be way better
// Go through every possible job and find the next one . // TODO : Some form of indexing would be way better
func (sched *Scheduled) FindNext() (int64, []*Command) {
	sched.mux.Lock()
	defer sched.mux.Unlock()
	minimum := int64(0)
	set := make([]*Command, 0)
	found := false
	for _, entry := range sched.Map.Users {
		for _, cmd := range entry.Commands {
			if !cmd.Pending {
				continue
			}
			start := cmd.NextRun - time.Now().Unix()
			if !found {
				minimum = start
				set = append(set, cmd)
				found = true
			} else if start <= minimum {
				if start < minimum {
					set = make([]*Command, 0)
				}
				minimum = start
				set = append(set, cmd)
			}
		}
	}
	if !found {
		return int64(60), nil
	}
	return minimum, set
}
func ( sched * Scheduled ) FindNext ( ) ( int64 , [ ] * Command ) { sched . mux . Lock ( ) defer sched . mux . Unlock ( ) minimum := int64 ( 0 ) set := make ( [ ] * Command , 0 ) found := false for _ , entry := range sched . Map . Users { for _ , cmd := range entry . Commands { if ! cmd . Pending { continue } start := cmd . NextRun - time . Now ( ) . Unix ( ) if ! found { minimum = start set = append ( set , cmd ) found = true } else if start <= minimum { if start < minimum { set = make ( [ ] * Command , 0 ) } minimum = start set = append ( set , cmd ) } } } if ! found { return int64 ( 60 ) , nil } return minimum , set }
Go through every possible job and find the next one.
Go through every possible job and find the next one .
// Full-table scan O(N) for all users, all jobs // We are okay, to do this in any order // Seconds until we should start this, can be negative // Reset the list