Console: Tag strings on /jobs (ticket #969)

This commit is contained in:
zzz
2013-09-29 16:36:32 +00:00
parent 2884df873e
commit 3cbfd09722

View File

@ -47,28 +47,29 @@ public class JobQueueHelper extends HelperBase {
int numRunners = _context.jobQueue().getJobs(readyJobs, timedJobs, activeJobs, justFinishedJobs); int numRunners = _context.jobQueue().getJobs(readyJobs, timedJobs, activeJobs, justFinishedJobs);
StringBuilder buf = new StringBuilder(32*1024); StringBuilder buf = new StringBuilder(32*1024);
buf.append("<b><div class=\"joblog\"><h3>I2P Job Queue</h3><br><div class=\"wideload\">Job runners: ").append(numRunners); buf.append("<b><div class=\"joblog\"><h3>").append(_("I2P Job Queue")).append("</h3><br><div class=\"wideload\">")
buf.append("</b><br>\n"); .append(_("Job runners")).append(": ").append(numRunners)
.append("</b><br>\n");
long now = _context.clock().now(); long now = _context.clock().now();
buf.append("<hr><b>Active jobs: ").append(activeJobs.size()).append("</b><ol>\n"); buf.append("<hr><b>").append(_("Active jobs")).append(": ").append(activeJobs.size()).append("</b><ol>\n");
for (int i = 0; i < activeJobs.size(); i++) { for (int i = 0; i < activeJobs.size(); i++) {
Job j = activeJobs.get(i); Job j = activeJobs.get(i);
buf.append("<li>[started ").append(DataHelper.formatDuration2(now-j.getTiming().getStartAfter())).append(" ago]: "); buf.append("<li>(").append(_("started {0} ago", DataHelper.formatDuration2(now-j.getTiming().getStartAfter()))).append("): ");
buf.append(j.toString()).append("</li>\n"); buf.append(j.toString()).append("</li>\n");
} }
buf.append("</ol>\n"); buf.append("</ol>\n");
buf.append("<hr><b>Just finished jobs: ").append(justFinishedJobs.size()).append("</b><ol>\n"); buf.append("<hr><b>").append(_("Just finished jobs")).append(": ").append(justFinishedJobs.size()).append("</b><ol>\n");
for (int i = 0; i < justFinishedJobs.size(); i++) { for (int i = 0; i < justFinishedJobs.size(); i++) {
Job j = justFinishedJobs.get(i); Job j = justFinishedJobs.get(i);
buf.append("<li>[finished ").append(DataHelper.formatDuration2(now-j.getTiming().getActualEnd())).append(" ago]: "); buf.append("<li>(").append(_("finished {0} ago", DataHelper.formatDuration2(now-j.getTiming().getActualEnd()))).append("): ");
buf.append(j.toString()).append("</li>\n"); buf.append(j.toString()).append("</li>\n");
} }
buf.append("</ol>\n"); buf.append("</ol>\n");
buf.append("<hr><b>Ready/waiting jobs: ").append(readyJobs.size()).append("</b><ol>\n"); buf.append("<hr><b>").append(_("Ready/waiting jobs")).append(": ").append(readyJobs.size()).append("</b><ol>\n");
ObjectCounter<String> counter = new ObjectCounter(); ObjectCounter<String> counter = new ObjectCounter();
for (int i = 0; i < readyJobs.size(); i++) { for (int i = 0; i < readyJobs.size(); i++) {
Job j = readyJobs.get(i); Job j = readyJobs.get(i);
@ -85,7 +86,7 @@ public class JobQueueHelper extends HelperBase {
out.write(buf.toString()); out.write(buf.toString());
buf.setLength(0); buf.setLength(0);
buf.append("<hr><b>Scheduled jobs: ").append(timedJobs.size()).append("</b><ol>\n"); buf.append("<hr><b>").append(_("Scheduled jobs")).append(": ").append(timedJobs.size()).append("</b><ol>\n");
long prev = Long.MIN_VALUE; long prev = Long.MIN_VALUE;
counter.clear(); counter.clear();
for (int i = 0; i < timedJobs.size(); i++) { for (int i = 0; i < timedJobs.size(); i++) {
@ -94,8 +95,9 @@ public class JobQueueHelper extends HelperBase {
if (i >= MAX_JOBS) if (i >= MAX_JOBS)
continue; continue;
long time = j.getTiming().getStartAfter() - now; long time = j.getTiming().getStartAfter() - now;
buf.append("<li>").append(j.getName()).append(" in "); // translators: {0} is a job name, {1} is a time, e.g. 6 min
buf.append(DataHelper.formatDuration2(time)); buf.append("<li>").append(_("{0} will start in {1}", j.getName(), DataHelper.formatDuration2(time)));
// debug, don't bother translating
if (time < 0) if (time < 0)
buf.append(" <b>DELAYED</b>"); buf.append(" <b>DELAYED</b>");
if (time < prev) if (time < prev)
@ -108,22 +110,22 @@ public class JobQueueHelper extends HelperBase {
out.write(buf.toString()); out.write(buf.toString());
buf.setLength(0); buf.setLength(0);
buf.append("<hr><b>Total Job Stats</b>\n"); buf.append("<hr><b>").append(_("Total Job Statistics")).append("</b>\n");
getJobStats(buf); getJobStats(buf);
out.write(buf.toString()); out.write(buf.toString());
} }
/** @since 0.9.5 */ /** @since 0.9.5 */
private static void getJobCounts(StringBuilder buf, ObjectCounter<String> counter) { private void getJobCounts(StringBuilder buf, ObjectCounter<String> counter) {
List<String> names = new ArrayList(counter.objects()); List<String> names = new ArrayList(counter.objects());
if (names.size() < 4) if (names.size() < 4)
return; return;
buf.append("<table style=\"width: 30%; margin-left: 100px;\">\n" + buf.append("<table style=\"width: 30%; margin-left: 100px;\">\n" +
"<tr><th>Job</th><th>Queued<th>"); "<tr><th>").append(_("Job")).append("</th><th>").append(_("Queued")).append("<th>");
Collections.sort(names, new JobCountComparator(counter)); Collections.sort(names, new JobCountComparator(counter));
for (String name : names) { for (String name : names) {
buf.append("<tr><td>").append(name) buf.append("<tr><td>").append(name)
.append("</td><td>").append(counter.count(name)) .append("</td><td align=\"center\">").append(counter.count(name))
.append("</td></tr>\n"); .append("</td></tr>\n");
} }
buf.append("</table>\n"); buf.append("</table>\n");
@ -136,9 +138,11 @@ public class JobQueueHelper extends HelperBase {
*/ */
private void getJobStats(StringBuilder buf) { private void getJobStats(StringBuilder buf) {
buf.append("<table>\n" + buf.append("<table>\n" +
"<tr><th>Job</th><th>Runs</th>" + "<tr><th>").append(_("Job")).append("</th><th>").append(_("Runs")).append("</th>" +
"<th>Time</th><th><i>Avg</i></th><th><i>Max</i></th><th><i>Min</i></th>" + "<th>").append(_("Time")).append("</th><th><i>").append(_("Avg")).append("</i></th><th><i>")
"<th>Pending</th><th><i>Avg</i></th><th><i>Max</i></th><th><i>Min</i></th></tr>\n"); .append(_("Max")).append("</i></th><th><i>").append(_("Min")).append("</i></th>" +
"<th>").append(_("Pending")).append("</th><th><i>").append(_("Avg")).append("</i></th><th><i>")
.append(_("Max")).append("</i></th><th><i>").append(_("Min")).append("</i></th></tr>\n");
long totRuns = 0; long totRuns = 0;
long totExecTime = 0; long totExecTime = 0;
long avgExecTime = 0; long avgExecTime = 0;
@ -186,7 +190,7 @@ public class JobQueueHelper extends HelperBase {
} }
buf.append("<tr class=\"tablefooter\">"); buf.append("<tr class=\"tablefooter\">");
buf.append("<td><b>").append("SUMMARY").append("</b></td>"); buf.append("<td><b>").append(_("Summary")).append("</b></td>");
buf.append("<td align=\"right\">").append(totRuns).append("</td>"); buf.append("<td align=\"right\">").append(totRuns).append("</td>");
buf.append("<td align=\"right\">").append(DataHelper.formatDuration2(totExecTime)).append("</td>"); buf.append("<td align=\"right\">").append(DataHelper.formatDuration2(totExecTime)).append("</td>");
buf.append("<td align=\"right\">").append(DataHelper.formatDuration2(avgExecTime)).append("</td>"); buf.append("<td align=\"right\">").append(DataHelper.formatDuration2(avgExecTime)).append("</td>");