mirror of
https://github.com/Fishwaldo/rundeck-api-java-client.git
synced 2025-07-08 14:08:33 +00:00
add 2 new methods for execution duration, that returns human-readable strings
This commit is contained in:
parent
3fb872d8a5
commit
46586235c4
4 changed files with 28 additions and 3 deletions
|
@ -18,6 +18,7 @@ package org.rundeck.api.domain;
|
|||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.apache.commons.lang.time.DurationFormatUtils;
|
||||
|
||||
/**
|
||||
* Represents a RunDeck execution, usually triggered by an API call. An execution could be a {@link RundeckJob}
|
||||
|
@ -72,6 +73,30 @@ public class RundeckExecution implements Serializable {
|
|||
return TimeUnit.MILLISECONDS.toSeconds(durationInMillis);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the duration of the execution, as a human-readable string : "3 minutes 34 seconds" (or null if the
|
||||
* duration is still running, or has been aborted)
|
||||
*/
|
||||
public String getDuration() {
|
||||
Long durationInMillis = getDurationInMillis();
|
||||
if (durationInMillis == null) {
|
||||
return null;
|
||||
}
|
||||
return DurationFormatUtils.formatDurationWords(durationInMillis, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the duration of the execution, as a "short" human-readable string : "0:03:34.187" (or null if the
|
||||
* duration is still running, or has been aborted)
|
||||
*/
|
||||
public String getShortDuration() {
|
||||
Long durationInMillis = getDurationInMillis();
|
||||
if (durationInMillis == null) {
|
||||
return null;
|
||||
}
|
||||
return DurationFormatUtils.formatDurationHMS(durationInMillis);
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ execution = rundeck.triggerJob("job-id", new Properties(opt: "value"), new Prope
|
|||
|
||||
// last one : you can run a job and wait until its execution is finished :
|
||||
execution = rundeck.runJob("job-id")
|
||||
println "Execution finished ! Status : ${execution.status}, duration (in seconds) : ${execution.durationInSeconds}"
|
||||
println "Execution finished ! Status : ${execution.status}, duration : ${execution.duration}"
|
||||
{code}
|
||||
|
||||
h2. Running an ad-hoc command
|
||||
|
|
|
@ -60,7 +60,7 @@ execution = rundeck.triggerJob("job-id", OptionsBuilder.new().addOption("opt", "
|
|||
|
||||
// last one : you can run a job and wait until its execution is finished :
|
||||
execution = rundeck.runJob("job-id")
|
||||
puts "Execution finished ! Status : #{execution.status}, duration (in seconds) : #{execution.durationInSeconds}"
|
||||
puts "Execution finished ! Status : #{execution.status}, duration : #{execution.duration}"
|
||||
{code}
|
||||
|
||||
h2. Running an ad-hoc command
|
||||
|
|
|
@ -45,7 +45,7 @@ execution = rundeck.triggerJob("job-id", OptionsBuilder().addOption("opt", "valu
|
|||
|
||||
// last one : you can run a job and wait until its execution is finished :
|
||||
execution = rundeck.runJob("job-id")
|
||||
print("Execution finished ! Status : %s, duration (in seconds) : %s" % (execution.status, execution.durationInSeconds))
|
||||
print("Execution finished ! Status : %s, duration : %s" % (execution.status, execution.duration))
|
||||
{code}
|
||||
|
||||
h2. Running an ad-hoc command
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue