package org.ngbw.utils; import java.util.concurrent.*; import org.ngbw.sdk.Workbench; import org.ngbw.sdk.tool.BaseProcessWorker; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** Run periodically to poll remote resources and find out which jobs have finished. We normally expect notification of job completion from a curl command in the remote job scripts but if the job timesout or something else goes wrong we may not be notified and need to poll. We check on all jobs that have a running_task table entry with status = SUBMITTED and our submitter id. If the jobs is completed we set it's status to DONE. The whole implementation is a static method in BaseProcessWorker. */ public class CheckJobs { private static final Log log = LogFactory.getLog(CheckJobs.class.getName()); private static String m_submitter; private static String m_default_submitter; private static long m_poll_interval; public static void main(String[] args) { try { Workbench wb = Workbench.getInstance(); log.debug("CHECK JOBS: workbench initialized."); m_default_submitter = wb.getProperties().getProperty("application.instance"); String p = wb.getProperties().getProperty("checkJobs.poll.seconds"); if (p == null) { throw new Exception("Missing workbench property: checkJobs.poll.seconds"); } m_poll_interval = new Long(p); m_submitter = System.getProperty("submitter"); if (m_submitter == null) { throw new Exception("Missing system property submitter"); } log.debug("Submitter=" + m_submitter + ", poll interval in seconds=" + m_poll_interval); while (true) { BaseProcessWorker.checkJobs(m_submitter); Thread.sleep(m_poll_interval * 1000); } } catch (Exception e) { log.error("", e); return; } } }