org.quartz.SchedulerException Java Examples

The following examples show how to use org.quartz.SchedulerException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XxlJobServiceImpl.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@Override
public ReturnT<String> remove(int id) {
	XxlJobInfo xxlJobInfo = xxlJobInfoDao.loadById(id);
       String group = String.valueOf(xxlJobInfo.getJobGroup());
       String name = String.valueOf(xxlJobInfo.getId());

	try {
		XxlJobDynamicScheduler.removeJob(name, group);
		xxlJobInfoDao.delete(id);
		xxlJobLogDao.delete(id);
		xxlJobLogGlueDao.deleteByJobId(id);
		return ReturnT.SUCCESS;
	} catch (SchedulerException e) {
		logger.error(e.getMessage(), e);
	}
	return ReturnT.FAIL;
}
 
Example #2
Source File: JobController.java    From opencron with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/edit")
public void edit(HttpSession session,HttpServletResponse response,Job job) throws SchedulerException {
    Job jober = jobService.getJob(job.getJobId());
    if (!jobService.checkJobOwner(session,jober.getUserId())) return;
    jober.setExecType(job.getExecType());
    jober.setCronType(job.getCronType());
    jober.setCommand(DigestUtils.passBase64(job.getCommand()));
    jober.setJobName(job.getJobName());
    jober.setRedo(job.getRedo());
    jober.setRunCount(job.getRunCount());
    jober.setWarning(job.getWarning());
    jober.setTimeout(job.getTimeout());
    if (jober.getWarning()) {
        jober.setMobiles(job.getMobiles());
        jober.setEmailAddress(job.getEmailAddress());
    }
    jober.setComment(job.getComment());
    jober.setUpdateTime(new Date());
    jobService.addOrUpdate(jober);
    schedulerService.syncJobTigger(jober.getJobId(),executeService);
    WebUtils.writeHtml(response, "success");
}
 
Example #3
Source File: StdSchedulerFactory.java    From AsuraFramework with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Returns a handle to the Scheduler produced by this factory.
 * </p>
 *
 * <p>
 * If one of the <code>initialize</code> methods has not be previously
 * called, then the default (no-arg) <code>initialize()</code> method
 * will be called by this method.
 * </p>
 */
public Scheduler getScheduler() throws SchedulerException {
    if (cfg == null) {
        initialize();
    }

    SchedulerRepository schedRep = SchedulerRepository.getInstance();

    Scheduler sched = schedRep.lookup(getSchedulerName());

    if (sched != null) {
        if (sched.isShutdown()) {
            schedRep.remove(getSchedulerName());
        } else {
            return sched;
        }
    }

    sched = instantiate();

    return sched;
}
 
Example #4
Source File: QssService.java    From seed with Apache License 2.0 6 votes vote down vote up
/**
 * 获取所有计划中的QuartzJob
 */
List<ScheduleTask> getAllJob(){
    try{
        List<ScheduleTask> taskList = new ArrayList<>();
        Set<JobKey> jobKeys = scheduler.getJobKeys(GroupMatcher.anyJobGroup());
        for(JobKey jobKey : jobKeys){
            List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
            for(Trigger trigger : triggers){
                taskList.add(this.convertToScheduleTask(jobKey, trigger));
            }
        }
        return taskList;
    }catch(SchedulerException e){
        throw new SeedException(CodeEnum.SYSTEM_ERROR.getCode(), "获取所有计划中的QuartzJob失败", e);
    }
}
 
Example #5
Source File: GCalPersistenceService.java    From openhab1-addons with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Delete all quartz scheduler jobs of the group <code>Dropbox</code>.
 */
private void cancelAllJobs() {
    try {
        Set<JobKey> jobKeys = scheduler.getJobKeys(jobGroupEquals(GCAL_SCHEDULER_GROUP));
        if (jobKeys.size() > 0) {
            scheduler.deleteJobs(new ArrayList<JobKey>(jobKeys));
            logger.debug("Found {} Google Calendar Upload-Jobs to delete from DefaulScheduler (keys={})",
                    jobKeys.size(), jobKeys);
        } else {
            logger.debug("Not found Google Calendar Upload to remove");
        }

    } catch (SchedulerException e) {
        logger.warn("Couldn't remove Google Calendar Upload-Job: {}", e.getMessage());
    }
}
 
Example #6
Source File: SchedulerKernel.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Shutsdown the application
 */
protected void shutdown() {
    try {
        SchedulerKernel.scheduler.standby();
        SchedulerKernel.scheduler.shutdown();
    }
    catch (SchedulerException e) {
        // TODO Figure out what to do with this guy
        e.printStackTrace();
    }
    finally {
        MessageQueue.stopMessaging();
        HibernateFactory.closeSessionFactory();
        // Wake up thread waiting in startup() so it can exit
        synchronized (this.shutdownLock) {
            this.shutdownLock.notify();
        }
    }
}
 
Example #7
Source File: SchedulingPullActions.java    From syncope with Apache License 2.0 6 votes vote down vote up
protected <T extends Job> void schedule(final Class<T> reference, final Map<String, Object> jobMap)
        throws JobExecutionException {

    @SuppressWarnings("unchecked")
    T jobInstance = (T) ApplicationContextProvider.getBeanFactory().
            createBean(reference, AbstractBeanDefinition.AUTOWIRE_BY_TYPE, false);
    String jobName = getClass().getName() + SecureRandomUtils.generateRandomUUID();

    jobMap.put(JobManager.DOMAIN_KEY, AuthContextUtils.getDomain());

    ApplicationContextProvider.getBeanFactory().registerSingleton(jobName, jobInstance);

    JobBuilder jobDetailBuilder = JobBuilder.newJob(reference).
            withIdentity(jobName).
            usingJobData(new JobDataMap(jobMap));

    TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger().
            withIdentity(JobNamer.getTriggerName(jobName)).
            startNow();

    try {
        scheduler.getScheduler().scheduleJob(jobDetailBuilder.build(), triggerBuilder.build());
    } catch (SchedulerException e) {
        throw new JobExecutionException("Could not schedule, aborting", e);
    }
}
 
Example #8
Source File: AdminEndpoint.java    From mercury with Apache License 2.0 6 votes vote down vote up
@PUT
@Path("/{name}")
@Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_HTML})
public Object startJob(@PathParam("name") String name) throws AppException, SchedulerException, IOException {
    ScheduledJob job = MainScheduler.getJob(name);
    if (job == null) {
        throw new AppException(404, "Job "+name+" not found");
    }
    if (job.startTime != null) {
        throw new IllegalArgumentException("Job "+name+" already started");
    }
    PostOffice.getInstance().broadcast(SCHEDULER_SERVICE, new Kv(ORIGIN, Platform.getInstance().getOrigin()),
                                        new Kv(TYPE, START), new Kv(JOB_ID, name));
    MainScheduler.startJob(job.name);
    Map<String, Object> result = new HashMap<>();
    result.put("type", "start");
    result.put("message", "Job "+name+" started");
    result.put("time", new Date());
    return result;
}
 
Example #9
Source File: TimerImpl.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean reschedule(AbstractInstant newTime) {
    try {
        Trigger trigger = newTrigger().startAt(newTime.toDate()).build();
        Date nextTriggerTime = scheduler.rescheduleJob(triggerKey, trigger);
        if (nextTriggerTime == null) {
            logger.debug("Scheduling a new job job '{}' because the original has already run", jobKey.toString());
            JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build();
            TimerImpl.scheduler.scheduleJob(job, trigger);
        }
        this.triggerKey = trigger.getKey();
        this.cancelled = false;
        this.terminated = false;
        return true;
    } catch (SchedulerException e) {
        logger.warn("An error occurred while rescheduling the job '{}': {}", jobKey.toString(), e.getMessage());
        return false;
    }
}
 
Example #10
Source File: AbstractQuartzScheduler.java    From deltaspike with Apache License 2.0 6 votes vote down vote up
private Trigger createTrigger(Scheduled scheduled, JobKey jobKey, String cronExpression) throws SchedulerException
{
    UUID triggerKey = UUID.randomUUID();

    if (!scheduled.cronExpression().endsWith(cronExpression))
    {
        createExpressionObserverJob(jobKey, triggerKey, scheduled.cronExpression(), cronExpression);
    }

    Trigger trigger = TriggerBuilder.newTrigger()
            .forJob(jobKey)
            .withIdentity(triggerKey.toString())
            .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression))
            .build();
    return trigger;
}
 
Example #11
Source File: ScriptExecution.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * helper function to create the timer
 *
 * @param instant the point in time when the code should be executed
 * @param closure string for job id
 * @param dataMap job data map, preconfigured with arguments
 * @return
 */
private static Timer makeTimer(AbstractInstant instant, String closure, JobDataMap dataMap) {

    Logger logger = LoggerFactory.getLogger(ScriptExecution.class);
    JobKey jobKey = new JobKey(instant.toString() + ": " + closure.toString());
    Trigger trigger = newTrigger().startAt(instant.toDate()).build();
    Timer timer = new TimerImpl(jobKey, trigger.getKey(), dataMap, instant);
    try {
        JobDetail job = newJob(TimerExecutionJob.class).withIdentity(jobKey).usingJobData(dataMap).build();
        if (TimerImpl.scheduler.checkExists(job.getKey())) {
            TimerImpl.scheduler.deleteJob(job.getKey());
            logger.debug("Deleted existing Job {}", job.getKey().toString());
        }
        TimerImpl.scheduler.scheduleJob(job, trigger);
        logger.debug("Scheduled code for execution at {}", instant.toString());
        return timer;
    } catch (SchedulerException e) {
        logger.error("Failed to schedule code for execution.", e);
        return null;
    }
}
 
Example #12
Source File: SchedulerServiceImplTest.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void scheduleJob(String groupName, String jobName, int startStep, int endStep, Date startTime, String requestorEmailAddress, Map<String,String> additionalJobData ) {
    Scheduler scheduler = (Scheduler) SpringContext.getService("scheduler");
    try {
        JobDetail jobDetail = scheduler.getJobDetail(jobName, groupName);
        if ( jobDetail == null ) {
            fail( "Unable to retrieve JobDetail object for " + groupName + " : " + jobName );
        }
        if ( jobDetail.getJobDataMap() == null ) {
            jobDetail.setJobDataMap( new JobDataMap() );
        }
        jobDetail.getJobDataMap().put(SchedulerService.JOB_STATUS_PARAMETER, SchedulerService.SCHEDULED_JOB_STATUS_CODE);
        scheduler.addJob(jobDetail, true);

        SimpleTriggerDescriptor trigger = new SimpleTriggerDescriptor(jobName+startTime, groupName, jobName, SpringContext.getBean(DateTimeService.class));
        trigger.setStartTime(startTime);
        Trigger qTrigger = trigger.getTrigger();
        qTrigger.getJobDataMap().put(JobListener.REQUESTOR_EMAIL_ADDRESS_KEY, requestorEmailAddress);
        qTrigger.getJobDataMap().put(Job.JOB_RUN_START_STEP, String.valueOf(startStep));
        qTrigger.getJobDataMap().put(Job.JOB_RUN_END_STEP, String.valueOf(endStep));
        if ( additionalJobData != null ) {
            qTrigger.getJobDataMap().putAll(additionalJobData);
        }
        scheduler.scheduleJob(qTrigger);
    }
    catch (SchedulerException e) {
        throw new RuntimeException("Caught exception while scheduling job: " + jobName, e);
    }
}
 
Example #13
Source File: QuartzManager.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
/**
 * get the job message
 *
 * @param jobName
 * @return
 */
public CEPRule getJobDetail(String jobName) throws SchedulerException, BrokerException {
    JobDetail job = scheduler.getJobDetail(new JobKey(jobName, "rule"));
    if (!StringUtils.isEmpty(job.getJobDataMap().get("rule"))) {
        return JsonHelper.json2Object(job.getJobDataMap().get("rule").toString(), CEPRule.class);
    }
    return null;
}
 
Example #14
Source File: XxlJobDynamicScheduler.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
/**
 * unscheduleJob
 *
 * @param jobName
 * @param jobGroup
 * @return
 * @throws SchedulerException
 */
public static boolean removeJob(String jobName, String jobGroup) throws SchedulerException {
	// TriggerKey : name + group
    TriggerKey triggerKey = TriggerKey.triggerKey(jobName, jobGroup);
    boolean result = false;
    if (checkExists(jobName, jobGroup)) {
        result = scheduler.unscheduleJob(triggerKey);
        logger.info(">>>>>>>>>>> removeJob, triggerKey:{}, result [{}]", triggerKey, result);
    }
    return true;
}
 
Example #15
Source File: RdbAnalyzeService.java    From redis-manager with Apache License 2.0 5 votes vote down vote up
@Override
public void updateJob(RDBAnalyze rdbAnalyze) {
    try {
        taskService.addTask(rdbAnalyze, RDBScheduleJob.class);
    } catch (SchedulerException e) {
        LOG.warn("schedule job update faild!message:{}", e.getMessage());
    }
}
 
Example #16
Source File: TaskoQuartzHelper.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * unschedules job
 * @param orgId organization id
 * @param jobLabel job name
 * @return 1 if successful
 */
public static Integer destroyJob(Integer orgId, String jobLabel) {
    try {
        SchedulerKernel.getScheduler()
                .unscheduleJob(triggerKey(jobLabel, getGroupName(orgId)));
        log.info("Job " + jobLabel + " unscheduled successfully.");
        return 1;
    }
    catch (SchedulerException e) {
        return null;
    }
}
 
Example #17
Source File: ScheduleService.java    From elasticsearch-quartz with Apache License 2.0 5 votes vote down vote up
public List<String> getTriggerGroupNames() {
    try {
        return scheduler.getTriggerGroupNames();
    } catch (final SchedulerException e) {
        throw new QuartzSchedulerException(e);
    }
}
 
Example #18
Source File: KENTestCase.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * This method makes sure to disable the Quartz scheduler
 * @throws SchedulerException
 */
protected void disableQuartzJobs() throws SchedulerException {
    // do this so that our quartz jobs don't go off - we don't care about
    // these in our unit tests
    Scheduler scheduler = services.getScheduler();
    scheduler.standby();
    //scheduler.shutdown();
}
 
Example #19
Source File: PropertySettingJobFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) throws SchedulerException {

    Job job = super.newJob(bundle, scheduler);
    
    JobDataMap jobDataMap = new JobDataMap();
    jobDataMap.putAll(scheduler.getContext());
    jobDataMap.putAll(bundle.getJobDetail().getJobDataMap());
    jobDataMap.putAll(bundle.getTrigger().getJobDataMap());

    setBeanProps(job, jobDataMap);
    
    return job;
}
 
Example #20
Source File: KCBInitializer.java    From rice with Educational Community License v2.0 5 votes vote down vote up
private void addTriggerToScheduler(Trigger trigger) throws SchedulerException {
       boolean triggerExists = (getScheduler().getTrigger(trigger.getKey()) != null);
	if (!triggerExists) {
		try {
			getScheduler().scheduleJob(trigger);
		} catch (ObjectAlreadyExistsException ex) {
               getScheduler().rescheduleJob(trigger.getKey(),trigger);
		}
	} else {
           getScheduler().rescheduleJob(trigger.getKey(),trigger);
	}
}
 
Example #21
Source File: RemoteScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * <p>
 * Calls the equivalent method on the 'proxied' <code>QuartzScheduler</code>.
 * </p>
 */
public void resumeAll() throws SchedulerException {
    try {
        getRemoteScheduler().resumeAll();
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}
 
Example #22
Source File: SchedulerAdapterTest.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobDataMapToXmlBuilder() throws SchedulerException {
	JobDataMap jobDataMap = new JobDataMap();
	jobDataMap.put(JAVALISTENER, "javaListener");
	jobDataMap.put(CORRELATIONID, "correlationId");
	jobDataMap.put(MESSAGE, "message");
	
	assertEquals("<jobMessages />", schedulerAdapter.getJobMessages(null).toXML().trim());
}
 
Example #23
Source File: TriggerCenterImpl.java    From cachecloud with Apache License 2.0 5 votes vote down vote up
/**
 * 恢复暂停的trigger
 *
 * @param triggerKey
 */
@Override
public boolean resumeTrigger(TriggerKey triggerKey) {
    boolean opResult = true;
    try {
        clusterScheduler.resumeTrigger(triggerKey);
    } catch (SchedulerException e) {
        logger.error(e.getMessage(), e);
        opResult = false;
    }
    return opResult;
}
 
Example #24
Source File: MpdBinding.java    From openhab1-addons with Eclipse Public License 2.0 5 votes vote down vote up
private void scheduleReconnect() {
    Scheduler sched;
    try {
        sched = StdSchedulerFactory.getDefaultScheduler();
        JobDetail job = newJob(ReconnectJob.class).withIdentity("Reconnect", MPD_SCHEDULER_GROUP).build();
        CronTrigger trigger = newTrigger().withIdentity("Reconnect", MPD_SCHEDULER_GROUP)
                .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 * * ?")).build();

        sched.scheduleJob(job, trigger);
        logger.debug("Scheduled a daily reconnect of all MPDs");
    } catch (SchedulerException se) {
        logger.warn("Scheduling MPD reconnect failed", se);
    }
}
 
Example #25
Source File: DefaultAutomaticScheduleManager.java    From niubi-job with Apache License 2.0 5 votes vote down vote up
private void resumeJob(JobKey jobKey) {
    try {
        scheduler.resumeJob(jobKey);
        LoggerHelper.info("job [" + jobKey.getGroup() + "," + jobKey.getName() + "] has been resumed.");
    } catch (SchedulerException e) {
        LoggerHelper.error("resume [" + jobKey.getGroup() + "," + jobKey.getName() + "] job failed.", e);
        throw new NiubiException(e);
    }
}
 
Example #26
Source File: ScheduleService.java    From elasticsearch-quartz with Apache License 2.0 5 votes vote down vote up
public void pauseJobs(final GroupMatcher<JobKey> matcher) {
    try {
        scheduler.pauseJobs(matcher);
    } catch (final SchedulerException e) {
        throw new QuartzSchedulerException(e);
    }
}
 
Example #27
Source File: SchedulerServiceSupplier.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Delete job.
 * 
 * @param jobName the job name
 * @param jobGroupName the job group name
 * 
 * @return the string
 */
public   String deleteJob(String jobName, String jobGroupName) {
	StringBuffer servreponse = new StringBuffer();
	try {
		Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); 
		servreponse.append("<EXECUTION_OUTCOME ");
		scheduler.deleteJob(jobName, jobGroupName);
		servreponse.append("outcome=\"perform\"/>");
	} catch (SchedulerException e) {
		SpagoBITracer.critical(SpagoBIConstants.NAME_MODULE, this.getClass().getName(), "deleteJob", 
				"Error while deleting job", e);
		servreponse.append("outcome=\"fault\"/>");
	}	
	return servreponse.toString();
}
 
Example #28
Source File: MessagingServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
private void scheduleJob() {
    LOG.debug("Queueing processing job");
    try {
        Scheduler scheduler = KSBServiceLocator.getScheduler();
        if (synchronous) {
            LOG.debug("Invoking job synchronously in Thread " + Thread.currentThread());
            MessageProcessingJob job = new MessageProcessingJob(messageId, mode, user, cause);
            job.run();
        } else {
            String uniqueTriggerName = jobName + "-Trigger-" + System.currentTimeMillis() + Math.random();
            SimpleTriggerImpl trigger = new SimpleTriggerImpl(uniqueTriggerName, jobGroup + "-Trigger");
            LOG.debug("Scheduling trigger: " + trigger);

            JobDataMap data = new JobDataMap();
            data.put("mode", mode.name());
            data.put("user", user);
            data.put("cause", cause);
            data.put("messageId", messageId);

            trigger.setJobName(jobName);
            trigger.setJobGroup(jobGroup);
            trigger.setJobDataMap(data);
            scheduler.scheduleJob(trigger);
        }
    } catch (SchedulerException se) {
        throw new RuntimeException(se);
    }
}
 
Example #29
Source File: DefaultSchedulerService.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public JobDetail getJobDetail(SchedulerJob schedulerJob) {
    try {
        List<JobDetail> jobs = QuartzUtil.getAllJobDetails(scheduler);
        for (JobDetail job : jobs) {
            //System.out.println("*** jobName=" + job.getName() + "  name=" + schedulerJob.getPath());
            if (job.getKey().getName().equals(schedulerJob.getPath())) {
                return job;
            }
        }
    } catch (SchedulerException e) {
        throw new RuntimeException(e);
    }
    
    return null;
}
 
Example #30
Source File: RemoteScheduler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public boolean unscheduleJobs(List<TriggerKey> triggerKeys)
        throws SchedulerException {
    try {
        return getRemoteScheduler().unscheduleJobs(triggerKeys);
    } catch (RemoteException re) {
        throw invalidateHandleCreateException(
                "Error communicating with remote scheduler.", re);
    }
}