Active Jobs Application

Last modified by Eduard Moraru on 2022/02/28 00:31

cogLists active jobs that are running inside your wiki.
TypeXAR
CategoryApplication
Developed by

Eduard Moraru, Guillaume Delhumeau, Gabriel Răileanu

Active Installs21
Rating
2 Votes
LicenseGNU Lesser General Public License 2.1

Installable with the Extension Manager

Description

This application lists the currently running jobs (as defined by the Job Module) or any grouped jobs that currently queued for execution and waiting for the group's actve job to finish. The current job of a job group could also be blocked by a Question (waiting for answer).

Any jobs that have already finished execution will not be listed here, as they are already sent to the Job Store.

Any jobs part of the Scheduler Application will not be listed here either, as they are handled differently.

Requires Programming Rights to function.

Screenshot

activeJobs1.png

Source

Below is the source to copy/paste in a new document in your XWiki instance, in case you can/will not use Extension Manager or direct XAR import to install it.

{{tree}}
{{groovy}}
xwiki.get("ssx").use("XWiki.ActiveJobs");

def jobExecutor = services.component.getInstance(org.xwiki.job.JobExecutor.class);

def jobs = new TreeMap(new Comparator<Object>() {
 public int compare(def one, def two) {
   return one.toString().compareTo(two.toString());
 }
});

// Note: Using private fields that are not exposed in APIs.
jobs.putAll(jobExecutor.groupExecutors);
jobs.putAll(jobExecutor.jobs);

for (def path : jobs.keySet()) {
 def pathJobOrExecutor = jobs.get(path);
 def isGroup = pathJobOrExecutor.getClass().getSimpleName().equals("JobGroupExecutor");

 if (isGroup) {
    println "* [Group] " + path;
    println "** executor: " + pathJobOrExecutor;

   def currentJob = pathJobOrExecutor.currentJob;
   if (currentJob != null) {
      displayJob(currentJob, "***");
   }

   def queue = pathJobOrExecutor.getQueue();
    println "*** Queue size: " + queue.size()
    queue.each {
      println "**** " + getJobName(it);
   }
 } else {
    displayJob(pathJobOrExecutor, "*");
 }
}

def getJobName(def job) {
 def result = "null";
 if (job != null) {
    result = org.apache.commons.lang3.StringUtils.join(job.getRequest().getId(), "/") + " (" + job.getClass().getName() + ")";
 }
 return result;
}

def displayJob(def job, def indentation) {
  println indentation + " [Job] " + getJobName(job)
 def jobStatus = job.getStatus();

  println indentation + "* Started at: " + jobStatus.getStartDate();

 def question = jobStatus.getQuestion();
 if (question != null) {
    println indentation + "* Question: " + question
    println indentation + "* Question ends in: " + ((long) (jobStatus.getQuestionTimeLeft(java.util.concurrent.TimeUnit.SECONDS)/1000000000)) + "s";
  }
  if (jobStatus instanceof org.xwiki.job.event.status.CancelableJobStatus) {
    def isCancelable = jobStatus.isCancelable()
    println indentation + "* Cancelable: " + isCancelable;
  }
}
{{/
groovy}}
{{tree}}

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.

You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:

  1. Log in the wiki with a user having Administration rights
  2. Go to the Administration page and select the Import category
  3. Follow the on-screen instructions to upload the downloaded XAR
  4. Click on the uploaded XAR and follow the instructions
  5. You'll also need to install all dependent Extensions that are not already installed in your wiki

Release Notes

v1.0

Initial release.

Get Connected