cron.go: disabling crons from crons page doesn't appear to do anything

Issue #177 resolved
Saxon Milton created an issue

Only getting this when we disable:

2022-05-23 06:53:01 default[7]  2022/05/23 06:53:01 setting cron: SensorPiOn
2022-05-23 06:53:01 default[7]  2022/05/23 06:53:01 cron: SensorPiOn with this spec, already exists, doing nothing

Comments (3)

  1. Saxon Milton reporter

    The culprit appears to be the check on line 8-9 below. This seems to check whether the state of the cron has changed or not, however this check is limited to the TOD, which wouldn’t detect a change in the Enabled field (among others). We should probably create a helper function that does a more extensive check on the job fields and returns a boolean to indicate whether it’s the same cron or not.

    // set install, updates or removes a cron job from the scheduler based on the
    // state of job.
    func (s *scheduler) set(job *iotds.Cron) error {
        log.Printf("setting cron: %v", job.ID)
        s.mu.Lock()
        defer s.mu.Unlock()
    
        id, ok := s.ids[cronID{Site: job.Skey, ID: job.ID}]
        if ok && s.entries[id].TOD == (*job).TOD {
            log.Printf("cron: %s with this spec, already exists, doing nothing", job.ID)
            // Do nothing since we already have this state.
            return nil
        }
    
        // Remove disabled crons.
        if !job.Enabled {
            if !ok {
                return nil
            }
            s.cron.Remove(id)
            delete(s.ids, cronID{Site: job.Skey, ID: job.ID})
            delete(s.entries, id)
            return nil
        }
    

  2. Saxon Milton reporter

    After further exploration it turns out an accidental regression was caused with this commit with removal of the isSameCron function which actually did do a proper check of the cron :/.

  3. Log in to comment