Add start times to tasks displayed by show-queue

Show-queue now displays the time each task was added to the queue, as
'HH:mm:ss.SSS' if recent, or 'MMM-dd HH:mm' if started more than a day ago.
Sample Output:

Task     State        StartTime         Command
------------------------------------------------------------------------------
59c06022              17:41:08.241      gerrit test-submit-rule (augale)
99da580d 18:39:53.921 17:39:53.922      Log File Compressor
------------------------------------------------------------------------------
  2 tasks

Change-Id: I4f013c941d8c86c2caaeccbbf13f2a9c6bd21a67
This commit is contained in:
Ahaan Ugale
2013-05-22 16:51:39 -06:00
parent 5ec7bab045
commit 50bc936427
2 changed files with 25 additions and 8 deletions

View File

@@ -94,10 +94,10 @@ final class ShowQueue extends SshCommand {
}
});
taskNameWidth = wide ? Integer.MAX_VALUE : columns - 8 - 12 - 8 - 4;
taskNameWidth = wide ? Integer.MAX_VALUE : columns - 8 - 12 - 12 - 4 - 4;
stdout.print(String.format("%-8s %-12s %-8s %s\n", //
"Task", "State", "", "Command"));
stdout.print(String.format("%-8s %-12s %-12s %-4s %s\n", //
"Task", "State", "StartTime", "", "Command"));
stdout.print("----------------------------------------------"
+ "--------------------------------\n");
@@ -149,10 +149,12 @@ final class ShowQueue extends SshCommand {
}
}
String startTime = startTime(task.getStartTime());
// Shows information about tasks depending on the user rights
if (viewAll || (!hasCustomizedPrint && regularUserCanSee)) {
stdout.print(String.format("%8s %-12s %-8s %s\n", //
id(task.getTaskId()), start, "", format(task)));
stdout.print(String.format("%8s %-12s %-12s %-4s %s\n", //
id(task.getTaskId()), start, startTime, "", format(task)));
} else if (regularUserCanSee) {
if (remoteName == null) {
remoteName = projectName.get();
@@ -160,8 +162,8 @@ final class ShowQueue extends SshCommand {
remoteName = remoteName + "/" + projectName;
}
stdout.print(String.format("%8s %-12s %-8s %s\n", //
id(task.getTaskId()), start, "", remoteName));
stdout.print(String.format("%8s %-12s %-4s %s\n", //
id(task.getTaskId()), start, startTime, "", remoteName));
}
}
stdout.print("----------------------------------------------"
@@ -180,7 +182,15 @@ final class ShowQueue extends SshCommand {
private static String time(final long now, final long delay) {
final Date when = new Date(now + delay);
if (delay < 24 * 60 * 60 * 1000L) {
return format(when, delay);
}
private static String startTime(final Date when) {
return format(when, System.currentTimeMillis() - when.getTime());
}
private static String format(final Date when, final long timeFromNow) {
if (timeFromNow < 24 * 60 * 60 * 1000L) {
return new SimpleDateFormat("HH:mm:ss.SSS").format(when);
}
return new SimpleDateFormat("MMM-dd HH:mm").format(when);