package org.ngbw.web.actions; import org.apache.log4j.Logger; import java.util.Date; import org.ngbw.sdk.database.RunningTask; import org.ngbw.sdk.tool.WorkQueue; /** * Job submissions scripts on remote hosts do a curl to this url to post * job status changes. *

* Struts.xml links this class to the url /portal2/taskupdate.action and * cipres-*.properties specifies that url as job.callback.url property, which * is passed to the ProcessWorker so it can pass it to the remote job script. */ @SuppressWarnings("serial") public class TaskUpdate extends NgbwSupport { private static final Logger logger = Logger.getLogger(TaskUpdate.class); @Override public String execute () { long taskId; String status; try { String tmp = getRequestParameter("taskId"); taskId = new Long(tmp); status = getRequestParameter("status"); if (status == null || (status = status.trim()).equals("")) { throw new Exception("missing status parameter"); } logger.debug("Got status:" + status + " for task:" + taskId); // throws a runtime exception (WorkbenchException) if record isn't found. // todo: should use jobhandle, not task id in the url, since taskids can be recycled when // task deleted. RunningTask rt = RunningTask.findRunningTaskByTask(taskId); if (status.equals("START")) { //rt.setStatus(RunningTask.STATUS_STARTED); WorkQueue.started(rt.getJobhandle(), rt.getRunNumber(), new Date()); } else if (status.equals("DONE")) { WorkQueue.markDone(rt); } else { throw new Exception("Unexpected job status. Task=" + taskId + ". Status=" + status); } return "success"; } catch ( Throwable t ) { logger.debug("", t); return "error"; } } }