@Override
  public void run() {
    try {
      if (!MetastoreConf.getBoolVar(conf, ConfVars.SCHEDULED_QUERIES_ENABLED)) {
        return;
      }
      RawStore ms = HMSHandler.getMSForConf(conf);

      int timeoutSecs = (int) MetastoreConf.getTimeVar(conf,
          MetastoreConf.ConfVars.SCHEDULED_QUERIES_EXECUTION_PROGRESS_TIMEOUT, TimeUnit.SECONDS);
      int timedOutCnt = ms.markScheduledExecutionsTimedOut(timeoutSecs);

      if (timedOutCnt > 0L) {
        LOG.info("Number of timed out scheduled query executions:" + timedOutCnt);
      }

      int maxRetainSecs = (int) MetastoreConf.getTimeVar(conf,
          MetastoreConf.ConfVars.SCHEDULED_QUERIES_EXECUTION_MAX_AGE, TimeUnit.SECONDS);
      int deleteCnt = ms.deleteScheduledExecutions(maxRetainSecs);

      if (deleteCnt > 0L){
        LOG.info("Number of deleted entries: " + deleteCnt);
      }
    } catch (Exception e) {
      LOG.error("Exception while trying to delete: " + e.getMessage(), e);
    }
  }
Metastore task to remove old scheduled query executions.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ScheduledQueryExecutionsMaintTask.java