private void register(BaseObject jobObj, XWikiContext context) throws SchedulerPluginException { String status = jobObj.getStringValue("status"); if (status.equals(JobState.STATE_NORMAL) || status.equals(JobState.STATE_PAUSED)) { scheduleJob(jobObj, context); } if (status.equals(JobState.STATE_PAUSED)) { pauseJob(jobObj, context); } }
/** * Return the trigger state as a ${@link JobState}, that holds both the integer trigger's inner value of the state * and a String as a human readable representation of that state */ public JobState getJobStatus(BaseObject object) throws SchedulerException { return getProtectedPlugin().getJobStatus(object, this.context); }
/** * Retrieve the job's status of a given {@link com.xpn.xwiki.plugin.scheduler.SchedulerPlugin#XWIKI_JOB_CLASS} job * XObject, by asking the actual job status to the quartz scheduler instance. It's the actual status, as the one * stored in the XObject may be changed manually by users. * * @param object the XObject to give the status of * @return the status of the Job inside the quartz scheduler, as {@link com.xpn.xwiki.plugin.scheduler.JobState} * instance */ public JobState getJobStatus(BaseObject object, XWikiContext context) throws SchedulerException { int state = getScheduler().getTriggerState(getObjectUniqueId(object, context), Scheduler.DEFAULT_GROUP); return new JobState(state); }
private void onWikiDeletedEvent(String wikiId) throws SchedulerException { Set<JobKey> keys = getScheduler().getJobKeys(GroupMatcher.anyJobGroup()); String idPrefix = getWikiIdPrefix(wikiId); for (JobKey key : keys) { if (key.getName().startsWith(idPrefix)) { getScheduler().deleteJob(key); } } }
String xjob = getObjectUniqueId(object, context); XWikiContext stubContext = prepareJobStubContext(object, context); data.put("context", stubContext); data.put("xcontext", stubContext); getScheduler().addJob(jobBuilder.build(), true); JobState status = getJobStatus(object, context); if (getTrigger(object, context).compareTo(trigger) != 0) { LOGGER.debug("Reschedule Job: [{}]", object.getStringValue("jobName")); getScheduler().rescheduleJob(trigger.getKey(), trigger); break; case NONE: LOGGER.debug("Schedule Job: [{}]", object.getStringValue("jobName")); getScheduler().scheduleJob(trigger); LOGGER.info("XWiki Job Status: [{}]", object.getStringValue("status")); if (object.getStringValue("status").equals("Paused")) { getScheduler().pauseJob(new JobKey(xjob)); saveStatus("Paused", object, context); } else { saveStatus("Normal", object, context); getScheduler().scheduleJob(trigger); saveStatus("Normal", object, context); break;
System.setProperty("org.quartz.threadPool.makeThreadsDaemons", "true"); setScheduler(getDefaultSchedulerInstance()); setStatusListener(); getScheduler().start(); restoreExistingJobs(xcontext);
/** * Resume the job with the given name (un-pause) * * @param object the non-wrapped XObject Job to be resumed */ public void resumeJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { try { getScheduler().resumeJob(getObjectUniqueId(object, context), Scheduler.DEFAULT_GROUP); saveStatus("Normal", object, context); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_RESUME_JOB, "Error occured while trying to resume job " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_RESUME_JOB, "Error occured while trying to save status of job " + object.getStringValue("jobName"), e); } }
public boolean scheduleJob(BaseObject object) { try { getProtectedPlugin().scheduleJob(object, this.context); return true; } catch (Exception e) { this.context.put("error", e.getMessage()); return false; } }
/** * Get the next fire time for the given job name SchedulerJob * * @param object unwrapped XObject job for which the next fire time will be given * @return the next Date the job will be fired at */ public Date getNextFireTime(BaseObject object, XWikiContext context) throws SchedulerPluginException { return getTrigger(object, context).getNextFireTime(); }
public Date getNextFireTime(BaseObject object) { try { return getProtectedPlugin().getNextFireTime(object, this.context); } catch (SchedulerPluginException e) { this.context.put("error", e.getMessage()); return null; } } }
public boolean pauseJob(BaseObject object) { try { getProtectedPlugin().pauseJob(object, this.context); LOG.debug("Pause Job : " + object.getStringValue("jobName")); return true; } catch (XWikiException e) { this.context.put("error", e.getMessage()); return false; } }
/** * Give, for a BaseObject job in a {@link JobState#STATE_NORMAL} state, the previous date at which the job has been * executed. Note that this method does not compute a date from the CRON expression, it only returns a date value * which is set each time the job is executed. If the job has never been fired this method will return null. * * @param object the BaseObject for which to give the fire time * @return the date the job has been executed */ public Date getPreviousFireTime(BaseObject object) { try { return getProtectedPlugin().getPreviousFireTime(object, this.context); } catch (SchedulerPluginException e) { this.context.put("error", e.getMessage()); return null; } }
/** * Associates the scheduler with a StatusListener * * @throws SchedulerPluginException if the status listener failed to be set properly */ private void setStatusListener() throws SchedulerPluginException { StatusListener listener = new StatusListener(); try { getScheduler().addSchedulerListener(listener); getScheduler().addGlobalJobListener(listener); } catch (SchedulerException e) { throw new SchedulerPluginException( SchedulerPluginException.ERROR_SCHEDULERPLUGIN_INITIALIZE_STATUS_LISTENER, "Error while initializing the status listener", e); } }
String xjob = getObjectUniqueId(object, context); XWikiContext stubContext = prepareJobStubContext(object, context); getScheduler().addJob(job, true); JobState status = getJobStatus(object, context); if (getTrigger(object, context).compareTo(trigger) != 0) { LOG.debug("Reschedule Job : " + object.getStringValue("jobName")); getScheduler().rescheduleJob(trigger.getName(), trigger.getGroup(), trigger); break; case Trigger.STATE_NONE: LOG.debug("Schedule Job : " + object.getStringValue("jobName")); getScheduler().scheduleJob(trigger); LOG.info("XWiki Job Status :" + object.getStringValue("status")); if (object.getStringValue("status").equals("Paused")) { getScheduler().pauseJob(xjob, Scheduler.DEFAULT_GROUP); saveStatus("Paused", object, context); } else { saveStatus("Normal", object, context); getScheduler().scheduleJob(trigger); saveStatus("Normal", object, context); break;
context.setDatabase(wikiName); try { updateSchedulerJobClass(context); } catch (Exception e) { LOG.error("Failed to update scheduler job class for in wiki [" + wikiName + "]", e); System.setProperty("org.quartz.threadPool.makeThreadsDaemons", "true"); setScheduler(getDefaultSchedulerInstance()); setStatusListener(); getScheduler().start(); restoreExistingJobs(context);
/** * Unschedule the given job * * @param object the unwrapped XObject job to be unscheduled */ public void unscheduleJob(BaseObject object, XWikiContext context) throws SchedulerPluginException { try { getScheduler().deleteJob(getObjectUniqueId(object, context), Scheduler.DEFAULT_GROUP); saveStatus("None", object, context); } catch (SchedulerException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while unscheduling job " + object.getStringValue("jobName"), e); } catch (XWikiException e) { throw new SchedulerPluginException(SchedulerPluginException.ERROR_SCHEDULERPLUGIN_JOB_XCLASS_NOT_FOUND, "Error while saving status of job " + object.getStringValue("jobName"), e); } }
public boolean scheduleJob(BaseObject object) { try { getProtectedPlugin().scheduleJob(object, this.context); return true; } catch (Exception e) { this.context.put("error", e.getMessage()); return false; } }
/** * Get the next fire time for the given job name SchedulerJob * * @param object unwrapped XObject job for which the next fire time will be given * @return the next Date the job will be fired at */ public Date getNextFireTime(BaseObject object, XWikiContext context) throws SchedulerPluginException { return getTrigger(object, context).getNextFireTime(); }
public Date getNextFireTime(BaseObject object) { try { return getProtectedPlugin().getNextFireTime(object, this.context); } catch (SchedulerPluginException e) { this.context.put("error", e.getMessage()); return null; } } }
public boolean pauseJob(BaseObject object) { try { getProtectedPlugin().pauseJob(object, this.context); LOGGER.debug("Pause Job: [{}]", object.getStringValue("jobName")); return true; } catch (XWikiException e) { this.context.put("error", e.getMessage()); return false; } }