Zdrojový kód wiki ActiveJobs
Naposledy upravil David Brazda 17.05.2021 10:34
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
![]() |
1.1 | 1 | {{tree}} |
| 2 | |||
| 3 | {{groovy}} | ||
| 4 | xwiki.get("ssx").use("XWiki.ActiveJobs"); | ||
| 5 | |||
| 6 | def jobExecutor = services.component.getInstance(org.xwiki.job.JobExecutor.class); | ||
| 7 | |||
| 8 | def jobs = new TreeMap(new Comparator<Object>() { | ||
| 9 | public int compare(def one, def two) { | ||
| 10 | return one.toString().compareTo(two.toString()); | ||
| 11 | } | ||
| 12 | }); | ||
| 13 | |||
| 14 | // Note: Using private fields that are not exposed in APIs. | ||
| 15 | jobs.putAll(jobExecutor.groupExecutors); | ||
| 16 | jobs.putAll(jobExecutor.jobs); | ||
| 17 | |||
| 18 | for (def path : jobs.keySet()) { | ||
| 19 | def pathJobOrExecutor = jobs.get(path); | ||
| 20 | def isGroup = pathJobOrExecutor.getClass().getSimpleName().equals("JobGroupExecutor"); | ||
| 21 | |||
| 22 | if (isGroup) { | ||
| 23 | println "* [Group] " + path; | ||
| 24 | println "** executor: " + pathJobOrExecutor; | ||
| 25 | |||
| 26 | def currentJob = pathJobOrExecutor.currentJob; | ||
| 27 | if (currentJob != null) { | ||
| 28 | displayJob(currentJob, "***"); | ||
| 29 | } | ||
| 30 | |||
| 31 | def queue = pathJobOrExecutor.getQueue(); | ||
| 32 | println "*** Queue size: " + queue.size() | ||
| 33 | queue.each { | ||
| 34 | println "**** " + getJobName(it); | ||
| 35 | } | ||
| 36 | } else { | ||
| 37 | displayJob(pathJobOrExecutor, "*"); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | def getJobName(def job) { | ||
| 42 | def result = "null"; | ||
| 43 | if (job != null) { | ||
| 44 | result = org.apache.commons.lang3.StringUtils.join(job.getRequest().getId(), "/") + " (" + job.getClass().getName() + ")"; | ||
| 45 | } | ||
| 46 | return result; | ||
| 47 | } | ||
| 48 | |||
| 49 | def displayJob(def job, def indentation) { | ||
| 50 | println indentation + " [Job] " + getJobName(job) | ||
| 51 | def jobStatus = job.getStatus(); | ||
| 52 | |||
| 53 | println indentation + "* Started at: " + jobStatus.getStartDate(); | ||
| 54 | |||
| 55 | def question = jobStatus.getQuestion(); | ||
| 56 | if (question != null) { | ||
| 57 | println indentation + "* Question: " + question | ||
| 58 | println indentation + "* Question ends in: " + ((long) (jobStatus.getQuestionTimeLeft(java.util.concurrent.TimeUnit.SECONDS)/1000000000)) + "s"; | ||
| 59 | } | ||
| 60 | if (jobStatus instanceof org.xwiki.job.event.status.CancelableJobStatus) { | ||
| 61 | def isCancelable = jobStatus.isCancelable() | ||
| 62 | println indentation + "* Cancelable: " + isCancelable; | ||
| 63 | } | ||
| 64 | } | ||
| 65 | {{/groovy}} | ||
| 66 | |||
| 67 | {{tree}} |
