public boolean checkAndDelete(String node, CuratorFramework zk) {
    JobState state = null;
    try {
      JobStateTracker tracker = new JobStateTracker(node, zk, true,
        appConf.get(TempletonStorage.STORAGE_ROOT +
          ZooKeeperStorage.TRACKINGDIR));
      long now = new Date().getTime();
      state = new JobState(tracker.getJobID(), appConf);

      // Set the default to 0 -- if the created date is null, there was
      // an error in creation, and we want to delete it anyway.
      long then = 0;
      if (state.getCreated() != null) {
        //this is set in ZooKeeperStorage.create()
        then = state.getCreated();
      }
      //todo: this should check that the job actually completed and likely use completion time
      //which is not tracked directly but available on /jobs/<id> node via "mtime" in Stat
      if (now - then > maxage) {
        LOG.info("Deleting " + tracker.getJobID());
        state.delete();
        tracker.delete();
        return true;
      }
      return false;
    } catch (Exception e) {
      LOG.info("checkAndDelete failed for " + node + " due to: " + e.getMessage());
      // We don't throw a new exception for this -- just keep going with the
      // next one.
      return true;
    } finally {
      if (state != null) {
        try {
          state.close();
        } catch (IOException e) {
          LOG.info("Couldn't close job state.");
        }
      }
    }
  }
Check to see if a job is more than maxage old, and delete it if so.
hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/tool/ZooKeeperCleanup.java