There is 1 comment.
 
 
XWiki Platform / cid:jira-generated-image-avatar-1f0d72aa-838d-4ac5-b34e-350c40fbe7a1 XWIKI-25789 Open

Rename jobs block on index update

 
View issue   ยท   Add comment
 

1 comment

 
cid:jira-generated-image-avatar-0928dbd4-6eb7-4701-b9a1-c569f16903f7 Jos on 17/Nov/26 16:12
 

Hi Thomas

 

I've managed to resolve the issue by using a groovy script to dispose the waiting tasks.

The problem seems to be resolved now, rename jobs are working

 

Code used to dispose:

{{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);
 // println " * " + pathJobOrExecutor.getClass().getName()
  def isGroup = pathJobOrExecutor.getClass().getSimpleName().equals("JobGroupExecutor");
  if (isGroup) {

    def currentJob = pathJobOrExecutor.currentJob;
    if (currentJob != null) {

      println "* [Group] " + path;
      println "** executor: " + pathJobOrExecutor;

      displayJob(currentJob, "***");

      def queue = pathJobOrExecutor.getQueue();
      println "*** Queue size: " + queue.size()
      queue.each {
        println "**** " + getJobName(it);
      }
      
      if (currentJob instanceof org.xwiki.refactoring.internal.job.MoveJob) {
        println "* move"
        def fields = pathJobOrExecutor.getClass().getDeclaredFields();
        for (f in fields) {
          if (f.getName().contains("this")) {
            f.setAccessible(true);
            def j = f.get(pathJobOrExecutor)
            j.dispose();
          }
        }
      }

    }

  } 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
    jobStatus.answered()
    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;
    if (job instanceof org.xwiki.refactoring.internal.job.MoveJob) {
      println indentation + "* job cancelled"
      job.join(1, java.util.concurrent.TimeUnit.MILLISECONDS)
    }
  }
}
{{/groovy}}
{{/tree}}