Search in sources :

Example 71 with Scheduler

use of org.quartz.Scheduler in project searchcode-server by boyter.

the class JobService method startDeleteJob.

/**
     * Starts a background job which deletes repositories from the database, index and checked out disk
     */
private void startDeleteJob() {
    try {
        Scheduler scheduler = Singleton.getScheduler();
        // Setup the indexer which runs forever adding documents to be indexed
        JobDetail job = newJob(DeleteRepositoryJob.class).withIdentity("deletejob").build();
        SimpleTrigger trigger = newTrigger().withIdentity("deletejob").withSchedule(simpleSchedule().withIntervalInSeconds(1).repeatForever()).build();
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
    } catch (SchedulerException ex) {
        Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 72 with Scheduler

use of org.quartz.Scheduler in project searchcode-server by boyter.

the class JobService method startIndexFileRepoJobs.

/**
     * Creates a file repo indexer job which will pull from the file queue and index
     */
public void startIndexFileRepoJobs(String uniquename) {
    try {
        Scheduler scheduler = Singleton.getScheduler();
        JobDetail job = newJob(IndexFileRepoJob.class).withIdentity("updateindex-file-" + uniquename).build();
        SimpleTrigger trigger = newTrigger().withIdentity("updateindex-file-" + uniquename).withSchedule(simpleSchedule().withIntervalInSeconds(this.INDEXTIME).repeatForever()).build();
        job.getJobDataMap().put("REPOLOCATIONS", this.REPOLOCATION);
        job.getJobDataMap().put("LOWMEMORY", this.LOWMEMORY);
        scheduler.scheduleJob(job, trigger);
        scheduler.start();
    } catch (SchedulerException ex) {
        Singleton.getLogger().severe(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
    }
}
Also used : JobDetail(org.quartz.JobDetail) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) SimpleTrigger(org.quartz.SimpleTrigger)

Example 73 with Scheduler

use of org.quartz.Scheduler in project engine by craftercms.

the class SiteContextFactory method scheduleJobs.

protected Scheduler scheduleJobs(SiteContext siteContext) {
    String siteName = siteContext.getSiteName();
    try {
        List<JobContext> allJobContexts = new ArrayList<>();
        for (ScriptJobResolver jobResolver : jobResolvers) {
            List<JobContext> jobContexts = jobResolver.resolveJobs(siteContext);
            if (CollectionUtils.isNotEmpty(jobContexts)) {
                allJobContexts.addAll(jobContexts);
            }
        }
        if (CollectionUtils.isNotEmpty(allJobContexts)) {
            Scheduler scheduler = SchedulingUtils.createScheduler(siteName + "_scheduler");
            logger.info("--------------------------------------------------");
            logger.info("<Scheduling job scripts for site: " + siteName + ">");
            logger.info("--------------------------------------------------");
            for (JobContext jobContext : allJobContexts) {
                scheduler.scheduleJob(jobContext.getDetail(), jobContext.getTrigger());
                logger.info("Scheduled job: " + jobContext + " for site '" + siteName + "'");
            }
            scheduler.start();
            logger.info("--------------------------------------------------");
            logger.info("</Scheduling job scripts for site: " + siteName + ">");
            logger.info("--------------------------------------------------");
            return scheduler;
        }
    } catch (Exception e) {
        logger.error("Unable to schedule jobs for site '" + siteName + "'", e);
    }
    return null;
}
Also used : Scheduler(org.quartz.Scheduler) ArrayList(java.util.ArrayList) ScriptJobResolver(org.craftercms.engine.scripting.ScriptJobResolver) JobContext(org.craftercms.engine.util.quartz.JobContext) SiteContextCreationException(org.craftercms.engine.exception.SiteContextCreationException) BeansException(org.springframework.beans.BeansException) ConfigurationException(org.apache.commons.configuration.ConfigurationException)

Aggregations

Scheduler (org.quartz.Scheduler)73 SchedulerException (org.quartz.SchedulerException)37 JobDetail (org.quartz.JobDetail)33 Trigger (org.quartz.Trigger)22 Test (org.junit.Test)19 JobKey (org.quartz.JobKey)17 SimpleTrigger (org.quartz.SimpleTrigger)16 CronTrigger (org.quartz.CronTrigger)15 JobDataMap (org.quartz.JobDataMap)10 TriggerKey (org.quartz.TriggerKey)10 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)6 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 IOException (java.io.IOException)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)3 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)3