func (jq *jobQueue) process(s *Scheduler) bool {

	select {
	case <-jq.stop:
		jq.health.Deregister() //nolint:errcheck
		return false
	case t := <-jq.bucketTicker.C:
		log.Tracef("Bucket ticked... current index: %v", jq.currentBucketIdx)
		jq.mu.Lock()
		if !jq.lastTick.Equal(time.Time{}) && t.After(jq.lastTick.Add(2*time.Second)) {
			log.Debugf("Previous bucket took over %v to schedule. Next checks will be running behind the schedule.", t.Sub(jq.lastTick))
		}
		jq.lastTick = t
		bucket := jq.buckets[jq.currentBucketIdx]
		jq.mu.Unlock()

		bucket.mu.RLock()
		// we have to copy to avoid blocking the bucket :(
		// blocking could interfere with scheduling new jobs
		jobs := []check.Check{}
		jobs = append(jobs, bucket.jobs...)
		bucket.mu.RUnlock()

		log.Tracef("Jobs in bucket: %v", jobs)

		for _, check := range jobs {
			if !s.IsCheckScheduled(check.ID()) {
				continue
			}

			select {
			// blocking, we'll be here as long as it takes
			case s.checksPipe <- check:
			case <-jq.stop:
				jq.health.Deregister() //nolint:errcheck
				return false
			}

			select {
			// we were able to schedule a check so we're not stuck, therefore poll the health chan
			case <-jq.health.C:
			default:
			}
		}
		jq.mu.Lock()
		jq.currentBucketIdx = (jq.currentBucketIdx + 1) % uint(len(jq.buckets))
		jq.mu.Unlock()
	case <-jq.health.C:
		// nothing
	}

	return true
}
// process  enqueues the checks at a tick, and returns whether the queue
// should listen to the following tick (or stop)
process  enqueues the checks at a tick, and returns whether the queue
should listen to the following tick (or stop)
// process enqueues the checks at a tick and returns whether the queue // should listen to the following tick ( or stop )
func (jq *jobQueue) process(s *Scheduler) bool {
	select {
	case <-jq.stop:
		jq.health.Deregister() 
		return false
	case t := <-jq.bucketTicker.C:
		log.Tracef("Bucket ticked... current index: %v", jq.currentBucketIdx)
		jq.mu.Lock()
		if !jq.lastTick.Equal(time.Time{}) && t.After(jq.lastTick.Add(2*time.Second)) {
			log.Debugf("Previous bucket took over %v to schedule. Next checks will be running behind the schedule.", t.Sub(jq.lastTick))
		}
		jq.lastTick = t
		bucket := jq.buckets[jq.currentBucketIdx]
		jq.mu.Unlock()
		bucket.mu.RLock()
		jobs := []check.Check{}
		jobs = append(jobs, bucket.jobs...)
		bucket.mu.RUnlock()
		log.Tracef("Jobs in bucket: %v", jobs)
		for _, check := range jobs {
			if !s.IsCheckScheduled(check.ID()) {
				continue
			}
			select {
			case s.checksPipe <- check:
			case <-jq.stop:
				jq.health.Deregister() 
				return false
			}
			select {
			case <-jq.health.C:
			default:
			}
		}
		jq.mu.Lock()
		jq.currentBucketIdx = (jq.currentBucketIdx + 1) % uint(len(jq.buckets))
		jq.mu.Unlock()
	case <-jq.health.C:
	}
	return true
}
func ( jq * jobQueue ) process ( s * Scheduler ) bool { select { case <- jq . stop : jq . health . Deregister ( ) return false case t := <- jq . bucketTicker . C : log . Tracef ( " " , jq . currentBucketIdx ) jq . mu . Lock ( ) if ! jq . lastTick . Equal ( time . Time { } ) && t . After ( jq . lastTick . Add ( 2 * time . Second ) ) { log . Debugf ( " " , t . Sub ( jq . lastTick ) ) } jq . lastTick = t bucket := jq . buckets [ jq . currentBucketIdx ] jq . mu . Unlock ( ) bucket . mu . RLock ( ) jobs := [ ] check . Check { } jobs = append ( jobs , bucket . jobs ... ) bucket . mu . RUnlock ( ) log . Tracef ( " " , jobs ) for _ , check := range jobs { if ! s . IsCheckScheduled ( check . ID ( ) ) { continue } select { case s . checksPipe <- check : case <- jq . stop : jq . health . Deregister ( ) return false } select { case <- jq . health . C : default : } } jq . mu . Lock ( ) jq . currentBucketIdx = ( jq . currentBucketIdx + 1 ) % uint ( len ( jq . buckets ) ) jq . mu . Unlock ( ) case <- jq . health . C : } return true }
process  enqueues the checks at a tick, and returns whether the queue
should listen to the following tick (or stop)
process enqueues the checks at a tick and returns whether the queue should listen to the following tick ( or stop )
//nolint:errcheck // we have to copy to avoid blocking the bucket :( // blocking could interfere with scheduling new jobs // blocking, we'll be here as long as it takes //nolint:errcheck // we were able to schedule a check so we're not stuck, therefore poll the health chan // nothing