public CompleteBean run(String id, String jobStatus)
    throws CallbackFailedException, IOException {
    if (id == null)
      acceptWithError("No jobid given");

    JobState state = null;
    /* we don't want to cancel the delegation token if we think the callback is going to
     to be retried, for example, because the job is not complete yet */
    boolean cancelMetastoreToken = false;
    try {
      state = new JobState(id, Main.getAppConfigInstance());
      if (state.getCompleteStatus() == null)
        failed("Job not yet complete. jobId=" + id + " Status from JobTracker=" + jobStatus, null);

      Long notified = state.getNotifiedTime();
      if (notified != null) {
        cancelMetastoreToken = true;
        return acceptWithError("Callback already run for jobId=" + id +
                " at " + new Date(notified));
      }

      String callback = state.getCallback();
      if (callback == null) {
        cancelMetastoreToken = true;
        return new CompleteBean("No callback registered");
      }
      
      try {
        doCallback(state.getId(), callback);
        cancelMetastoreToken = true;
      } catch (Exception e) {
        failed("Callback failed " + callback + " for " + id, e);
      }

      state.setNotifiedTime(System.currentTimeMillis());
      return new CompleteBean("Callback sent");
    } finally {
      state.close();
      IMetaStoreClient client = null;
      try {
        if(cancelMetastoreToken) {
          String metastoreTokenStrForm =
                  DelegationTokenCache.getStringFormTokenCache().getDelegationToken(id);
          if(metastoreTokenStrForm != null) {
            client = HCatUtil.getHiveMetastoreClient(new HiveConf());
            client.cancelDelegationToken(metastoreTokenStrForm);
            LOG.debug("Cancelled token for jobId=" + id + " status from JT=" + jobStatus);
            DelegationTokenCache.getStringFormTokenCache().removeDelegationToken(id);
          }
        }
      }
      catch(Exception ex) {
        LOG.warn("Failed to cancel metastore delegation token for jobId=" + id, ex);
      }
      finally {
        HCatUtil.closeHiveClientQuietly(client);
      }
    }
  }
Complete a job.  This will run the callback if

- the job is done
- there is a callback
- the callback has not yet been called

There is a small chance for a race condition if two callers run
this at the same time.  That should never happen.

We use a Hadoop config var to notify this class on the completion
of a job.  Hadoop will call us multiple times in the event of
failure.  Even if the failure is that the client callback failed.

See LauncherDelegator for the HADOOP_END_RETRY* vars that are set.
hcatalog/webhcat/svr/src/main/java/org/apache/hive/hcatalog/templeton/CompleteDelegator.java