// timeBasedCleaner deletes those znodes in the base path older than t. func timeBasedCleaner(client *ezk.Client, base string, t time.Duration) error { now := unixMilli() // Read all the childrens children, _, err := client.Children(base) if err != nil { return err } // Iterate to all the childrents reading the creation time millis := int64(t / time.Millisecond) for i := range children { node := join(base, children[i]) ok, stat, err := client.Exists(node) if err != nil { return err } // Delete locks older than SchedulerLockTime if ok && stat.Ctime+millis < now { if err := client.Delete(node, stat.Version); err != nil && err != zk.ErrNoNode { return err } } } return nil }