To List All Jobs
Jobs fall into one of four categories: completed, queued, scheduled, and running. To list each job requires iterating through all the categories.
var categories = ["running", "completed", "scheduled", "queued"];
listJobCategory(categories);
}
function listJobCategory(categories)
{
if (categories.length == 0)
{
return;
}
category = categories.shift();
httpRequest.open("GET", "/fmerest/jobs/"+category+".json?token="+token_, true);
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
var reply = eval("(" + httpRequest.responseText + ")");
if (typeof(reply.serviceResponse.jobs.job) != 'undefined')
{
var jobs = reply.serviceResponse.jobs.job;
var output = new Array();
for (var i in jobs)
{
output.push(jobs[i].ID);
}
println(category);
println(output.join(","));
}
else
{
println("No Parameters Found");
}
}
else
{
println("Error");
}
listJobCategory(categories);
}
}
httpRequest.send(null);
}
To View the Details of a Job
To view the details of a job, the job ID is required.
httpRequest.open("GET", "/fmerest/jobs/"+id+".json?token="+token_, true);
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
var reply = eval("(" + httpRequest.responseText + ")");
var job = reply.serviceResponse.job;
// display any details here
println("ID: " + job.ID);
println("Status: " + job.jobStatus);
}
else
{
println("Error");
}
}
}
httpRequest.send(null);
To Delete Finished Jobs
As jobs are completed, the list of finished jobs accumulates. To clear the list of finished jobs, simply send a DELETE request.
httpRequest.open("DELETE", "/fmerest/jobs/completed.xml?token="+token_, true);
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
println("Completed jobs removed");
}
else
{
println("Failed to remove completed jobs");
}
}
}
httpRequest.send(null);
To Cancel a Queued Job
To cancel a queued job, the job ID is required.
httpRequest.open("DELETE", "/fmerest/jobs/"+id+"/cancel.json?token="+token_, true);
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState == 4)
{
if (httpRequest.status == 200)
{
println("Job cancelled");
}
else
{
println("Failed to cancel job");
}
}
}
httpRequest.send(null);