@Transactional(rollbackFor = Exception.class) public void delete(Long jobId) throws SchedulerException { Job job = getJob(jobId); if (job != null) { //单一任务,直接执行删除 String sql = "UPDATE T_JOB SET deleted=1 WHERE "; if (job.getJobType().equals(JobType.SINGLETON.getCode())) { sql += " jobId=" + jobId; } if (job.getJobType().equals(JobType.FLOW.getCode())) { if (job.getFlowNum() == 0) { //顶层流程任务,则删除一组 sql += " flowId=" + job.getFlowId(); } else { //其中一个子流程任务,则删除单个 sql += " jobId=" + jobId; } } queryDao.createSQLQuery(sql).executeUpdate(); schedulerService.syncJobTigger(jobId, null); flushJob(); } }
/** * Resume paused job */ @Override public boolean resumeJob(String jobName) { System.out.println("Request received for resuming job."); String jobKey = jobName; String groupKey = "SampleGroup"; JobKey jKey = new JobKey(jobKey, groupKey); System.out.println("Parameters received for resuming job : jobKey :"+jobKey); try { schedulerFactoryBean.getScheduler().resumeJob(jKey); System.out.println("Job with jobKey :"+jobKey+ " resumed succesfully."); return true; } catch (SchedulerException e) { System.out.println("SchedulerException while resuming job with key :"+jobKey+ " message :"+e.getMessage()); e.printStackTrace(); return false; } }
/** * Remove the indicated Trigger from the scheduler. * If the related job does not have any other triggers, and the job is not durable, then the job will also be deleted. */ @Override public boolean unScheduleJob(String jobName) { System.out.println("Request received for Unscheduleding job."); String jobKey = jobName; TriggerKey tkey = new TriggerKey(jobKey); System.out.println("Parameters received for unscheduling job : tkey :"+jobKey); try { boolean status = schedulerFactoryBean.getScheduler().unscheduleJob(tkey); System.out.println("Trigger associated with jobKey :"+jobKey+ " unscheduled with status :"+status); return status; } catch (SchedulerException e) { System.out.println("SchedulerException while unscheduling job with key :"+jobKey + " message :"+e.getMessage()); e.printStackTrace(); return false; } }
private boolean notifyTriggerListenersComplete(JobExecutionContext jobExCtxt, CompletedExecutionInstruction instCode) { try { qs.notifyTriggerListenersComplete(jobExCtxt, instCode); } catch (SchedulerException se) { qs.notifySchedulerListenersError( "Unable to notify TriggerListener(s) of Job that was executed: " + "(error will be ignored). trigger= " + jobExCtxt.getTrigger().getKey() + " job= " + jobExCtxt.getJobDetail().getKey(), se); return false; } if (jobExCtxt.getTrigger().getNextFireTime() == null) { qs.notifySchedulerListenersFinalized(jobExCtxt.getTrigger()); } return true; }
@Test public void assertExecute() throws SchedulerException { Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.of(new JobRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3))); Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.of(new TaskRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3))); when(repository.findLatestJobRunningStatistics()).thenReturn(latestJobRunningStatistics); when(repository.findLatestTaskRunningStatistics()).thenReturn(latestTaskRunningStatistics); when(repository.add(any(JobRunningStatistics.class))).thenReturn(true); when(repository.add(any(TaskRunningStatistics.class))).thenReturn(true); Map<String, Set<TaskContext>> jobMap = new HashMap<>(1); Set<TaskContext> jobSet = new HashSet<>(1); jobSet.add(TaskContext.from(TaskNode.builder().jobName("test_job").build().getTaskNodeValue())); jobMap.put("test_job", jobSet); when(runningService.getAllRunningTasks()).thenReturn(jobMap); jobRunningStatisticJob.execute(null); verify(repository).findLatestJobRunningStatistics(); verify(repository).findLatestTaskRunningStatistics(); verify(repository, times(3)).add(any(JobRunningStatistics.class)); verify(repository, times(3)).add(any(TaskRunningStatistics.class)); verify(runningService).getAllRunningTasks(); }
@Transactional(rollbackFor = Exception.class) public void stopNow(Integer id) { JobDetailDO jobDetailDO = daoSupport.get(id, JobDetailDO.class); if (Objects.isNull(jobDetailDO) || jobDetailDO.getState().intValue() != 1) { throw new BusinessException(ExceptionEnum.FAIL); } //先保留原状态,原表达式。 Integer origState = jobDetailDO.getState(); String origCron = jobDetailDO.getCron(); //调用任务处理service,删除job。 jobDetailDO.setState(2); try { initJobService.deleteJob(jobDetailDO); } catch (SchedulerException e) { e.printStackTrace(); throw new BusinessException(ExceptionEnum.FAIL); } //增加操作记录 JobDetailEditAO jobDetailEditAO = buildJobDetailEditAO(origState, origCron, JobDetailEditTypeEnum.DELETE.getCode(), jobDetailDO); jobDetailEditNotesService.addEditNote(jobDetailEditAO); }
public List<ScheduleJob> getAllJobList(){ List<ScheduleJob> jobList = new ArrayList<>(); try { GroupMatcher<JobKey> matcher = GroupMatcher.anyJobGroup(); Set<JobKey> jobKeySet = scheduler.getJobKeys(matcher); for (JobKey jobKey : jobKeySet){ List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey); for (Trigger trigger : triggers){ ScheduleJob scheduleJob = new ScheduleJob(); this.wrapScheduleJob(scheduleJob,scheduler,jobKey,trigger); jobList.add(scheduleJob); } } } catch (SchedulerException e) { e.printStackTrace(); } return jobList; }
private boolean notifyJobListenersComplete(JobExecutionContext jec, JobExecutionException jobExEx) { try { qs.notifyJobListenersWasExecuted(jec, jobExEx); } catch (SchedulerException se) { qs.notifySchedulerListenersError( "Unable to notify JobListener(s) of Job that was executed: " + "(error will be ignored). trigger= " + jec.getTrigger().getFullName() + " job= " + jec.getJobDetail().getFullName(), se); return false; } return true; }
public boolean deleteJobs(List<JobKey> jobKeys) throws SchedulerException { validateState(); boolean result = false; result = resources.getJobStore().removeJobs(jobKeys); notifySchedulerThread(0L); for(JobKey key: jobKeys) notifySchedulerListenersJobDeleted(key); return result; }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>. * </p> */ public void shutdown() throws SchedulerException { try { String schedulerName = getSchedulerName(); getRemoteScheduler().shutdown(); SchedulerRepository.getInstance().remove(schedulerName); } catch (RemoteException re) { throw invalidateHandleCreateException( "Error communicating with remote scheduler.", re); } }
@Test public void assertExecute() throws SchedulerException { Optional<JobRegisterStatistics> latestOne = Optional.of(new JobRegisterStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.DAY, -3))); when(repository.findLatestJobRegisterStatistics()).thenReturn(latestOne); when(repository.add(any(JobRegisterStatistics.class))).thenReturn(true); when(configurationService.loadAll()).thenReturn(Lists.newArrayList(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job"))); registeredJobStatisticJob.execute(null); verify(repository).findLatestJobRegisterStatistics(); verify(repository, times(3)).add(any(JobRegisterStatistics.class)); verify(configurationService).loadAll(); }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>. * </p> */ public void resumeTrigger(TriggerKey triggerKey) throws SchedulerException { try { getRemoteScheduler().resumeTrigger(triggerKey); } catch (RemoteException re) { throw invalidateHandleCreateException( "Error communicating with remote scheduler.", re); } }
public void destroy() { if (schedulerOn) { try { sched.shutdown(); } catch (SchedulerException e) { Engine.logEngine.error("Unexpected exception", e); } finally { schedulerOn = false; } } }
private void pauseJobs() throws SchedulerException { for (final Iterator i = triggerKeyList.iterator(); i.hasNext();) { final TriggerKey key = (TriggerKey) i.next(); //if (log.isDebugEnabled()) log.debug("pausing: " + key.toString()); scheduler.pauseTrigger(key.getName(), key.getGroup()); } }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>. * </p> */ public void start() throws SchedulerException { try { getRemoteScheduler().start(); } catch (RemoteException re) { throw invalidateHandleCreateException( "Error communicating with remote scheduler.", re); } }
@Override public List<TriggerDefinition> getTriggersForJob(NameAndGroup jobKey) { try { JobKey quartzJobKey = new JobKey(jobKey.getName(), jobKey.getGroup()); return scheduler.getTriggersOfJob(quartzJobKey).stream() .map(quartzToCronyxSelector::convert) .map(this::enhanceTriggerDefinition) .collect(Collectors.toList()); } catch (SchedulerException e) { throw new SchedulingException(e); } }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>, * passing the <code>SchedulingContext</code> associated with this * instance. * </p> */ public boolean deleteJob(String jobName, String groupName) throws SchedulerException { return ((Boolean)invoke( "deleteJob", new Object[] { schedulingContext, jobName, groupName}, new String[] { SchedulingContext.class.getName(), String.class.getName(), String.class.getName() })).booleanValue(); }
@Override public void resumeAll() { try { scheduler.resumeAll(); } catch (SchedulerException e) { throw new SchedulingException(e); } }
/** * <p> * Get the names of all the <code>{@link org.quartz.Trigger}s</code> in * the given group. * </p> */ public String[] getTriggerNames(SchedulingContext ctxt, String groupName) throws SchedulerException { validateState(); if(groupName == null) { groupName = Scheduler.DEFAULT_GROUP; } return resources.getJobStore().getTriggerNames(ctxt, groupName); }
/** * @param tabularData * @return array of region statistics */ public static TabularData toTabularData( final List<JobExecutionContext> executingJobs) throws SchedulerException { List<CompositeData> list = new ArrayList<CompositeData>(); for (final Iterator<JobExecutionContext> iter = executingJobs .iterator(); iter.hasNext();) { list.add(toCompositeData(iter.next())); } TabularData td = new TabularDataSupport(TABULAR_TYPE); td.putAll(list.toArray(new CompositeData[list.size()])); return td; }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>, * passing the <code>SchedulingContext</code> associated with this * instance. * </p> */ public String[] getJobNames(String groupName) throws SchedulerException { try { return getRemoteScheduler().getJobNames(schedCtxt, groupName); } catch (RemoteException re) { throw invalidateHandleCreateException( "Error communicating with remote scheduler.", re); } }
@Override public List<Trigger> triggers() { try { List<? extends Trigger> triggersOfJob = quartzScheduler.getTriggersOfJob(nodeCrontabDetail.getKey()); return Lists.newArrayList(triggersOfJob); } catch (SchedulerException e) { throw new IllegalStatusException(e.getMessage()); } }
void start() { scheduler = getScheduler(); try { scheduler.start(); } catch (final SchedulerException ex) { throw new JobSystemException(ex); } }
private void scheduleTrigger(TriggerKey triggerKey, String contextKey) { try { OnDemandTrigger trigger = (OnDemandTrigger) scheduler.getTrigger(triggerKey); trigger.getJobDataMap().put(CONTEXT_KEY, contextKey); trigger.setNextFireTimeToNow(); scheduler.rescheduleJob(triggerKey, trigger); } catch (SchedulerException e) { throw new CronyxException("Could not fire trigger: " + triggerKey.toString(), e); } }
public void addJob(JobDetail jobDetail, boolean replace, boolean storeNonDurableWhileAwaitingScheduling) throws SchedulerException { validateState(); if (!storeNonDurableWhileAwaitingScheduling && !jobDetail.isDurable()) { throw new SchedulerException( "Jobs added with no trigger must be durable."); } resources.getJobStore().storeJob(jobDetail, replace); notifySchedulerThread(0L); notifySchedulerListenersJobAdded(jobDetail); }
public String generateInstanceId() throws SchedulerException { try { return InetAddress.getLocalHost().getHostName(); } catch (Exception e) { throw new SchedulerException("Couldn't get host name!", e); } }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>, * passing the <code>SchedulingContext</code> associated with this * instance. * </p> */ public Date scheduleJob(JobDetail jobDetail, Trigger trigger) throws SchedulerException { return (Date)invoke( "scheduleJob", new Object[] { schedulingContext, jobDetail, trigger }, new String[] { SchedulingContext.class.getName(), JobDetail.class.getName(), Trigger.class.getName() }); }
@Override public boolean isRunning() throws SchedulingException { if (this.scheduler != null) { try { return !this.scheduler.isInStandbyMode(); } catch (SchedulerException ex) { return false; } } return false; }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>, * passing the <code>SchedulingContext</code> associated with this * instance. * </p> */ public Trigger[] getTriggersOfJob(String jobName, String groupName) throws SchedulerException { return (Trigger[])invoke( "getTriggersOfJob", new Object[] { schedulingContext, jobName, groupName }, new String[] { SchedulingContext.class.getName(), String.class.getName(), String.class.getName() }); }
@Override public JobDefinition getJobByKey(NameAndGroup nameAndGroup) { try { JobDetail jobDetail = scheduler.getJobDetail(JobKey.jobKey(nameAndGroup.getName(), nameAndGroup.getGroup())); if (jobDetail != null) { return (JobDefinition) jobDetail .getJobDataMap() .get(Constants.JOB_DEFINITION); } else { return null; } } catch (SchedulerException e) { throw new CronyxException(e); } }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>. * </p> */ public Set<JobKey> getJobKeys(GroupMatcher<JobKey> matcher) throws SchedulerException { try { return getRemoteScheduler().getJobKeys(matcher); } catch (RemoteException re) { throw invalidateHandleCreateException( "Error communicating with remote scheduler.", re); } }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>, * passing the <code>SchedulingContext</code> associated with this * instance. * </p> */ public boolean unscheduleJob(TriggerKey triggerKey) throws SchedulerException { return (Boolean)invoke( "unscheduleJob", new Object[] { triggerKey.getName(), triggerKey.getGroup() }, new String[] { String.class.getName(), String.class.getName() }); }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>. * </p> */ public void shutdown() throws SchedulerException { // Have to get the scheduler name before we actually call shutdown. String schedulerName = getSchedulerName(); invoke("shutdown", new Object[] {}, new String[] {}); SchedulerRepository.getInstance().remove(schedulerName); }
/** * <p> * Get all <code>{@link Trigger}</code> s that are associated with the * identified <code>{@link org.quartz.JobDetail}</code>. * </p> */ public Trigger[] getTriggersOfJob(SchedulingContext ctxt, String jobName, String groupName) throws SchedulerException { validateState(); if(groupName == null) { groupName = Scheduler.DEFAULT_GROUP; } return resources.getJobStore().getTriggersForJob(ctxt, jobName, groupName); }
/** * @see org.quartz.Scheduler#interrupt(JobKey) */ public boolean interrupt(JobKey jobKey) throws UnableToInterruptJobException { try { return (Boolean)invoke( "interruptJob", new Object[] { jobKey.getName(), jobKey.getGroup() }, new String[] { String.class.getName(), String.class.getName() }); } catch (SchedulerException se) { throw new UnableToInterruptJobException(se); } }
/** * <p> * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>. * </p> */ public void addGlobalTriggerListener(TriggerListener triggerListener) throws SchedulerException { throw new SchedulerException( "Operation not supported for remote schedulers.", SchedulerException.ERR_UNSUPPORTED_FUNCTION_IN_THIS_CONFIGURATION); }
private List<TriggerListener> buildTriggerListenerList() throws SchedulerException { List<TriggerListener> allListeners = new LinkedList<TriggerListener>(); allListeners.addAll(getListenerManager().getTriggerListeners()); allListeners.addAll(getInternalTriggerListeners()); return allListeners; }
/** * 获取所有的Trigger * @param schedulerName * @return * @throws SchedulerException */ public List<? extends Trigger> getAllTriggersOfScheduler(String schedulerName) throws SchedulerException { List<Trigger> triggersOfScheduler = new ArrayList<Trigger>(); Scheduler scheduler = this.getAssertScheduler(schedulerName); List<JobDetail> jobDetails = getAllJobsOfScheduler(schedulerName); for (JobDetail jobDetail : jobDetails) { List<? extends Trigger> triggersOfJob = QuartzUtils.getTriggersOfJob(jobDetail, scheduler); triggersOfScheduler.addAll(triggersOfJob); } return triggersOfScheduler; }
public void removeJob(String schedulerName, String jobName, String jobGroup) throws SchedulerException { Assert.notEmpty(jobName, "jobName can not be empty"); Assert.notEmpty(jobGroup, "jobGroup can not be empty"); Scheduler scheduler = this.getAssertScheduler(schedulerName); if (!existJob(schedulerName, jobName, jobGroup)) { throw new IllegalArgumentException("job [" + jobName + ":" + jobGroup + "] not exist"); } // 暂停 QuartzUtils.pauseJob(jobName, jobGroup, scheduler); // 移除 QuartzUtils.removeJob(jobName, jobGroup, scheduler); }
/** * 初始化作业. */ public void init() { JobDetail jobDetail = JobBuilder.newJob(DaemonJob.class).withIdentity(jobRootConfig.getTypeConfig().getCoreConfig().getJobName()).build(); jobDetail.getJobDataMap().put(ELASTIC_JOB_DATA_MAP_KEY, elasticJob); jobDetail.getJobDataMap().put(JOB_FACADE_DATA_MAP_KEY, jobFacade); jobDetail.getJobDataMap().put(EXECUTOR_DRIVER_DATA_MAP_KEY, executorDriver); jobDetail.getJobDataMap().put(TASK_ID_DATA_MAP_KEY, taskId); try { scheduleJob(initializeScheduler(), jobDetail, taskId.getValue(), jobRootConfig.getTypeConfig().getCoreConfig().getCron()); } catch (final SchedulerException ex) { throw new JobSystemException(ex); } }