Search in sources :

Example 91 with CronTrigger

use of org.quartz.CronTrigger in project new-cloud by xie-summer.

the class BaseJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    // 是否已执行业务逻辑
    boolean isExecute = false;
    // 业务逻辑执行后返回结果
    boolean flag = false;
    try {
        // 可以通过context拿到执行当前任务的quartz中的很多信息,如当前是哪个trigger在执行该任务
        CronTrigger trigger = (CronTrigger) context.getTrigger();
        String corn = trigger.getCronExpression();
        String jobName = trigger.getKey().getName();
        String jobGroup = trigger.getKey().getGroup();
    } catch (Exception e) {
    }
}
Also used : CronTrigger(org.quartz.CronTrigger) JobExecutionException(org.quartz.JobExecutionException)

Example 92 with CronTrigger

use of org.quartz.CronTrigger in project zeppelin by apache.

the class QuartzSchedulerService method refreshCron.

@Override
public boolean refreshCron(String noteId) throws IOException {
    removeCron(noteId);
    return notebook.processNote(noteId, note -> {
        if (note == null) {
            LOGGER.warn("Skip refresh cron of note: {} because there's no such note", noteId);
            return false;
        }
        if (note.isTrash()) {
            LOGGER.warn("Skip refresh cron of note: {} because it is in trash", noteId);
            return false;
        }
        Map<String, Object> config = note.getConfig();
        if (config == null) {
            LOGGER.warn("Skip refresh cron of note: {} because its config is empty.", noteId);
            return false;
        }
        if (!note.isCronSupported(zeppelinConfiguration)) {
            LOGGER.warn("Skip refresh cron of note {} because its cron is not enabled.", noteId);
            return false;
        }
        String cronExpr = (String) note.getConfig().get("cron");
        if (cronExpr == null || cronExpr.trim().length() == 0) {
            LOGGER.warn("Skip refresh cron of note {} because its cron expression is empty.", noteId);
            return false;
        }
        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.put("notebook", notebook);
        jobDataMap.put("noteId", noteId);
        JobDetail newJob = JobBuilder.newJob(CronJob.class).withIdentity(noteId, "note").setJobData(jobDataMap).build();
        Map<String, Object> info = note.getInfo();
        info.put("cron", null);
        CronTrigger trigger = null;
        try {
            trigger = TriggerBuilder.newTrigger().withIdentity("trigger_" + noteId, "note").withSchedule(CronScheduleBuilder.cronSchedule(cronExpr)).forJob(noteId, "note").build();
        } catch (Exception e) {
            LOGGER.error("Fail to create cron trigger for note: {}", noteId, e);
            info.put("cron", e.getMessage());
            return false;
        }
        try {
            LOGGER.info("Trigger cron for note: {}, with cron expression: {}", noteId, cronExpr);
            scheduler.scheduleJob(newJob, trigger);
            return true;
        } catch (SchedulerException e) {
            LOGGER.error("Fail to schedule cron job for note: {}", noteId, e);
            info.put("cron", "Scheduler Exception");
            return false;
        }
    });
}
Also used : JobDataMap(org.quartz.JobDataMap) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) SchedulerException(org.quartz.SchedulerException)

Example 93 with CronTrigger

use of org.quartz.CronTrigger in project SSM by Intel-bigdata.

the class Notebook method refreshCron.

public void refreshCron(String id) {
    removeCron(id);
    synchronized (notes) {
        Note note = notes.get(id);
        if (note == null) {
            return;
        }
        Map<String, Object> config = note.getConfig();
        if (config == null) {
            return;
        }
        String cronExpr = (String) note.getConfig().get("cron");
        if (cronExpr == null || cronExpr.trim().length() == 0) {
            return;
        }
        JobDetail newJob = JobBuilder.newJob(CronJob.class).withIdentity(id, "note").usingJobData("noteId", id).build();
        Map<String, Object> info = note.getInfo();
        info.put("cron", null);
        CronTrigger trigger = null;
        try {
            trigger = TriggerBuilder.newTrigger().withIdentity("trigger_" + id, "note").withSchedule(CronScheduleBuilder.cronSchedule(cronExpr)).forJob(id, "note").build();
        } catch (Exception e) {
            logger.error("Error", e);
            info.put("cron", e.getMessage());
        }
        try {
            if (trigger != null) {
                quartzSched.scheduleJob(newJob, trigger);
            }
        } catch (SchedulerException e) {
            logger.error("Error", e);
            info.put("cron", "Scheduler Exception");
        }
    }
}
Also used : JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) AngularObject(org.apache.zeppelin.display.AngularObject) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) JobExecutionException(org.quartz.JobExecutionException)

Example 94 with CronTrigger

use of org.quartz.CronTrigger in project spring-framework by spring-projects.

the class CronTriggerFactoryBeanTests method createWithoutJobDetail.

@Test
public void createWithoutJobDetail() throws ParseException {
    CronTriggerFactoryBean factory = new CronTriggerFactoryBean();
    factory.setName("myTrigger");
    factory.setCronExpression("0 15 10 ? * *");
    factory.afterPropertiesSet();
    CronTrigger trigger = factory.getObject();
    assertThat(trigger.getCronExpression()).isEqualTo("0 15 10 ? * *");
}
Also used : CronTrigger(org.quartz.CronTrigger) Test(org.junit.jupiter.api.Test)

Example 95 with CronTrigger

use of org.quartz.CronTrigger in project alfresco-remote-api by Alfresco.

the class RepositoryContainerTest method testLargeContentRequest.

/*
     * Test for MNT-11237 : CMIS uploading file larger the 4mb fails
     * 
     * Tests that requests with content larger than 4mb (default memoryThreshold value) can be successfully handled by repository container 
     */
public void testLargeContentRequest() throws Exception {
    authenticationComponent.setCurrentUser(USER_ONE);
    // create the 5 mb size buffer of zero bytes
    byte[] content = new byte[5 * 1024 * 1024];
    Arrays.fill(content, (byte) 0);
    // chek that we can upload file larger than 4 mb
    Response response = sendRequest(new PutRequest("/test/largecontenttest", content, "text/plain"), STATUS_OK);
    assertEquals(SUCCESS, response.getContentAsString());
    // trigger the webscript temp folder cleaner job
    CronTrigger webscriptsTempFileCleanerJobTrigger = (CronTrigger) getServer().getApplicationContext().getBean("webscripts.tempFileCleanerTrigger");
    Scheduler scheduler = (Scheduler) getServer().getApplicationContext().getBean("schedulerFactory");
    scheduler.triggerJob(webscriptsTempFileCleanerJobTrigger.getJobKey());
    // check that we still can upload file larger than 4 mb, i.e. ensure that cleaner has not deleted temp folder
    response = sendRequest(new PutRequest("/test/largecontenttest", content, "text/plain"), STATUS_OK);
    assertEquals(SUCCESS, response.getContentAsString());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) CronTrigger(org.quartz.CronTrigger) Scheduler(org.quartz.Scheduler) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)

Aggregations

CronTrigger (org.quartz.CronTrigger)103 JobDetail (org.quartz.JobDetail)42 Trigger (org.quartz.Trigger)36 SimpleTrigger (org.quartz.SimpleTrigger)29 SchedulerException (org.quartz.SchedulerException)28 Test (org.junit.Test)24 Scheduler (org.quartz.Scheduler)19 TriggerKey (org.quartz.TriggerKey)19 Date (java.util.Date)14 JobKey (org.quartz.JobKey)12 JobDataMap (org.quartz.JobDataMap)11 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)8 CronScheduleBuilder (org.quartz.CronScheduleBuilder)8 ParseException (java.text.ParseException)7 HashMap (java.util.HashMap)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 JobExecutionException (org.quartz.JobExecutionException)6 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)5 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)5