Examples - Show Running Tasks

This Java example shows how to use the "queryRunningTasks" function to find out what tasks are currently running. Remember that this call can only be made by users in the MOVEit Log and/or MOVEit Admin groups.

Setup

To run this example you should have a few long running, active tasks in MOVEit Automation.

Example Run

Assuming you are in the samples directory

java -cp .;..\MICentralAPI.jar ShowRunningTasks
Scheduler Status: On
Tasks Running: 1
===== Download from DMZ via FTP (434384185) =====
=  Started : 2007-10-25 14:17:53 ((a local user))
=  Status  : Finding matching files on 192.168.19.205
Full XML Reply:
<Response>
  <CmdName>SHOWRUNNINGTASKS</CmdName>
  <ReqID>3</ReqID>
  <RepCode>0</RepCode>
  <RepText></RepText>
  <Time>2007-10-25 14:17:55</Time>
  <Output><Tasks><SchedulerStatus>On</SchedulerStatus>
<Task><TaskID>434384185</TaskID>
<TaskName>Download from DMZ</TaskName>
<NominalStart>2007-10-25 14:17:53</NominalStart>
<TimeStarted>2007-10-25 14:17:53</TimeStarted>
<StartedBy>(a local user)</StartedBy>
<Status>Finding matching files on 192.168.19.205</Status>
<CurFileBytes>0</CurFileBytes>
<TotFileBytes>-1</TotFileBytes>
<LastErrorType>0</LastErrorType>
<LastErrorText></LastErrorText>
</Task>

</Tasks></Output>
</Response>

Code Excerpts

The main body of the example highlights how to get information about the currently running tasks. The information returned by the call to "queryRunningTasks" is an XML structure. Documentation for this XML structure is available here.

String replyXML = oAPI.queryRunningTasks();

if (replyXML.equals("")) {
	showMsg("Failed to get status: " + oAPI.getErrorDescription());
	return;
}

The XML result contains a list of the active tasks. In this example the XML is parsed into a DOM Document object and then XPath is used to select the Task nodes. The XPath to get the Task nodes is /Response/Output/Tasks/Task.

Document replyDoc = parse_xml(replyXML);

Node outputNode = get_node_xpath(replyDoc.getDocumentElement(), 
	"/Response/Output");

showMsg("Scheduler Status: " + get_node_value_xpath((Element)outputNode, 
	"Tasks/SchedulerStatus"));

NodeList taskNodes = get_nodes_xpath((Element)outputNode, "Tasks/Task");

Once the list of Task nodes is resolved, the code loops each node and then accesses information about the task - such as the TaskName element.

showMsg("Tasks Running: " + taskNodes.getLength());

if (taskNodes.getLength() > 0) {
	Element taskEle = null;
	
	for (int i = 0; i < taskNodes.getLength(); i++) {
		taskEle = (Element)(taskNodes.item(i));
		
		showMsg("===== " + get_subnode_value(taskEle,"TaskName") + 
			" (" + get_subnode_value(taskEle,"TaskID") + ") =====");
			
		showMsg("=  Started : " + get_subnode_value(taskEle,"TimeStarted") + 
			" (" + get_subnode_value(taskEle,"StartedBy") + ")");
			
		String shortStatus = get_subnode_value(taskEle,"Status");
		
		if (shortStatus.length() > 50) {
			shortStatus = shortStatus.substring(0,50) + "...";
		}
		
		showMsg("=  Status  : " + shortStatus);
		
		if (Long.valueOf(get_subnode_value(taskEle,"TotFileBytes")) > 0) {
			showMsg("=  Transfer: " + 
				get_subnode_value(taskEle,"CurFileBytes") +
				" of " + get_subnode_value(taskEle,"TotFileBytes") + 
				" bytes");
		}
	}
}

showMsg("Full XML Reply:");
showMsg(replyXML);