Search in sources :

Example 71 with SimpleTrigger

use of org.quartz.SimpleTrigger in project pentaho-platform by pentaho.

the class QuartzScheduler method createQuartzTrigger.

public static Trigger createQuartzTrigger(IJobTrigger jobTrigger, QuartzJobKey jobId) throws SchedulerException {
    Trigger quartzTrigger = null;
    if (jobTrigger instanceof ComplexJobTrigger) {
        try {
            quartzTrigger = new CronTrigger(jobId.toString(), jobId.getUserName(), jobTrigger.getCronString() != null ? jobTrigger.getCronString() : QuartzCronStringFactory.createCronString((ComplexJobTrigger) jobTrigger));
        } catch (ParseException e) {
            throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0001_FAILED_TO_SCHEDULE_JOB", jobId.getJobName()), // $NON-NLS-1$
            e);
        }
    } else if (jobTrigger instanceof SimpleJobTrigger) {
        SimpleJobTrigger simpleTrigger = (SimpleJobTrigger) jobTrigger;
        long interval = simpleTrigger.getRepeatInterval();
        if (interval > 0) {
            interval *= 1000;
        }
        int repeatCount = simpleTrigger.getRepeatCount() < 0 ? SimpleTrigger.REPEAT_INDEFINITELY : simpleTrigger.getRepeatCount();
        quartzTrigger = new SimpleTrigger(jobId.toString(), jobId.getUserName(), simpleTrigger.getStartTime(), simpleTrigger.getEndTime(), repeatCount, interval);
    } else {
        // $NON-NLS-1$
        throw new SchedulerException(Messages.getInstance().getString("QuartzScheduler.ERROR_0002_TRIGGER_WRONG_TYPE"));
    }
    quartzTrigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
    if (quartzTrigger instanceof SimpleTrigger) {
        if (((SimpleTrigger) quartzTrigger).getRepeatCount() != 0) {
            quartzTrigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT);
        }
    }
    return quartzTrigger;
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) CronTrigger(org.quartz.CronTrigger) CronTrigger(org.quartz.CronTrigger) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) JobTrigger(org.pentaho.platform.api.scheduler2.JobTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) IJobTrigger(org.pentaho.platform.api.scheduler2.IJobTrigger) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) ParseException(java.text.ParseException) SimpleTrigger(org.quartz.SimpleTrigger)

Example 72 with SimpleTrigger

use of org.quartz.SimpleTrigger in project pentaho-platform by pentaho.

the class QuartzScheduler method setJobTrigger.

private void setJobTrigger(Scheduler scheduler, Job job, Trigger trigger) throws SchedulerException, org.quartz.SchedulerException {
    QuartzJobKey jobKey = QuartzJobKey.parse(job.getJobId());
    String groupName = jobKey.getUserName();
    if (trigger instanceof SimpleTrigger) {
        SimpleTrigger simpleTrigger = (SimpleTrigger) trigger;
        SimpleJobTrigger simpleJobTrigger = new SimpleJobTrigger();
        simpleJobTrigger.setStartTime(simpleTrigger.getStartTime());
        simpleJobTrigger.setEndTime(simpleTrigger.getEndTime());
        simpleJobTrigger.setUiPassParam((String) job.getJobParams().get(RESERVEDMAPKEY_UIPASSPARAM));
        long interval = simpleTrigger.getRepeatInterval();
        if (interval > 0) {
            interval /= 1000;
        }
        simpleJobTrigger.setRepeatInterval(interval);
        simpleJobTrigger.setRepeatCount(simpleTrigger.getRepeatCount());
        job.setJobTrigger(simpleJobTrigger);
    } else if (trigger instanceof CronTrigger) {
        CronTrigger cronTrigger = (CronTrigger) trigger;
        ComplexJobTrigger complexJobTrigger = createComplexTrigger(cronTrigger.getCronExpression());
        complexJobTrigger.setUiPassParam((String) job.getJobParams().get(RESERVEDMAPKEY_UIPASSPARAM));
        complexJobTrigger.setCronString(((CronTrigger) trigger).getCronExpression());
        job.setJobTrigger(complexJobTrigger);
        if (trigger.getCalendarName() != null) {
            Calendar calendar = scheduler.getCalendar(trigger.getCalendarName());
            if (calendar instanceof QuartzSchedulerAvailability) {
                QuartzSchedulerAvailability quartzSchedulerAvailability = (QuartzSchedulerAvailability) calendar;
                complexJobTrigger.setStartTime(quartzSchedulerAvailability.getStartTime());
                complexJobTrigger.setEndTime(quartzSchedulerAvailability.getEndTime());
            }
        }
        complexJobTrigger.setCronString(((CronTrigger) trigger).getCronExpression());
    }
    int triggerState = scheduler.getTriggerState(job.getJobId(), groupName);
    switch(triggerState) {
        case Trigger.STATE_NORMAL:
            job.setState(JobState.NORMAL);
            break;
        case Trigger.STATE_BLOCKED:
            job.setState(JobState.BLOCKED);
            break;
        case Trigger.STATE_COMPLETE:
            job.setState(JobState.COMPLETE);
            break;
        case Trigger.STATE_ERROR:
            job.setState(JobState.ERROR);
            break;
        case Trigger.STATE_PAUSED:
            job.setState(JobState.PAUSED);
            break;
        default:
            job.setState(JobState.UNKNOWN);
            break;
    }
    job.setJobName(QuartzJobKey.parse(job.getJobId()).getJobName());
    job.setNextRun(trigger.getNextFireTime());
    job.setLastRun(trigger.getPreviousFireTime());
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) CronTrigger(org.quartz.CronTrigger) ComplexJobTrigger(org.pentaho.platform.api.scheduler2.ComplexJobTrigger) Calendar(org.quartz.Calendar) SimpleTrigger(org.quartz.SimpleTrigger)

Example 73 with SimpleTrigger

use of org.quartz.SimpleTrigger in project BIMserver by opensourceBIM.

the class JobScheduler method addRecurringJob.

private void addRecurringJob(Class<? extends Job> class1, int intervalMillis) throws SchedulerException {
    SimpleTrigger trigger = newTrigger().withIdentity("group1", class1.getSimpleName()).withSchedule(simpleSchedule().withIntervalInMilliseconds(intervalMillis).repeatForever()).build();
    JobDetail job = newJob(class1).withIdentity("group1", class1.getSimpleName()).build();
    sched.scheduleJob(job, trigger);
}
Also used : JobDetail(org.quartz.JobDetail) SimpleTrigger(org.quartz.SimpleTrigger)

Example 74 with SimpleTrigger

use of org.quartz.SimpleTrigger in project weicoder by wdcode.

the class SimpleTriggerPersistenceDelegate method updateExtendedTriggerProperties.

public int updateExtendedTriggerProperties(Connection conn, OperableTrigger trigger, String state, JobDetail jobDetail) throws SQLException, IOException {
    SimpleTrigger simpleTrigger = (SimpleTrigger) trigger;
    PreparedStatement ps = null;
    try {
        ps = conn.prepareStatement(Util.rtp(UPDATE_SIMPLE_TRIGGER, tablePrefix, schedNameLiteral));
        ps.setInt(1, simpleTrigger.getRepeatCount());
        ps.setBigDecimal(2, new BigDecimal(String.valueOf(simpleTrigger.getRepeatInterval())));
        ps.setInt(3, simpleTrigger.getTimesTriggered());
        ps.setString(4, simpleTrigger.getKey().getName());
        ps.setString(5, simpleTrigger.getKey().getGroup());
        return ps.executeUpdate();
    } finally {
        Util.closeStatement(ps);
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) SimpleTrigger(org.quartz.SimpleTrigger) BigDecimal(java.math.BigDecimal)

Example 75 with SimpleTrigger

use of org.quartz.SimpleTrigger in project iaf by ibissource.

the class ShowScheduler method trigger.

@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/schedules/{groupName}/job/{jobName}")
@Relation("schedules")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response trigger(@PathParam("jobName") String jobName, @PathParam("groupName") String groupName, LinkedHashMap<String, Object> json) throws ApiException {
    Scheduler scheduler = getScheduler();
    if (log.isInfoEnabled()) {
        String commandIssuedBy = request.getRemoteHost();
        commandIssuedBy += "-" + request.getRemoteAddr();
        commandIssuedBy += "-" + request.getRemoteUser();
        log.info("trigger job jobName [" + jobName + "] groupName [" + groupName + "] " + commandIssuedBy);
    }
    JobKey jobKey = JobKey.jobKey(jobName, groupName);
    // PAUSE,RESUME,TRIGGER
    String action = "";
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        if (key.equalsIgnoreCase("action")) {
            // Start or stop an adapter!
            action = (String) entry.getValue();
        }
    }
    try {
        if ("pause".equals(action)) {
            scheduler.pauseJob(jobKey);
        } else if ("resume".equals(action)) {
            SchedulerHelper sh = getSchedulerHelper();
            JobDetail jobDetail = scheduler.getJobDetail(jobKey);
            // TODO this part can be more generic in case multiple triggers
            // can be configurable
            List<? extends Trigger> triggers = scheduler.getTriggersOfJob(jobKey);
            if (triggers != null) {
                for (Trigger trigger : triggers) {
                    if (trigger instanceof CronTrigger) {
                        sh.scheduleJob(jobDetail, ((CronTrigger) trigger).getCronExpression(), -1, true);
                    } else if (trigger instanceof SimpleTrigger) {
                        sh.scheduleJob(jobDetail, null, ((SimpleTrigger) trigger).getRepeatInterval(), true);
                    }
                }
            }
            scheduler.resumeJob(jobKey);
        } else if ("trigger".equals(action)) {
            scheduler.triggerJob(jobKey);
        } else {
            throw new ApiException("no (valid) action provided! Expected one of PAUSE,RESUME,TRIGGER");
        }
    } catch (SchedulerException e) {
        throw new ApiException("Failed to " + action + " job", e);
    }
    return Response.status(Response.Status.OK).build();
}
Also used : CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) JobKey(org.quartz.JobKey) JobDetail(org.quartz.JobDetail) IbisJobDetail(nl.nn.adapterframework.scheduler.IbisJobDetail) SchedulerHelper(nl.nn.adapterframework.scheduler.SchedulerHelper) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) SimpleTrigger(org.quartz.SimpleTrigger) List(java.util.List) ArrayList(java.util.ArrayList) SimpleTrigger(org.quartz.SimpleTrigger) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Aggregations

SimpleTrigger (org.quartz.SimpleTrigger)75 CronTrigger (org.quartz.CronTrigger)27 SchedulerException (org.quartz.SchedulerException)27 JobDetail (org.quartz.JobDetail)24 Date (java.util.Date)22 Scheduler (org.quartz.Scheduler)21 Trigger (org.quartz.Trigger)20 Test (org.junit.Test)11 JobDataMap (org.quartz.JobDataMap)11 ArrayList (java.util.ArrayList)9 JobDetailBean (org.springframework.scheduling.quartz.JobDetailBean)8 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 SimpleDateFormat (java.text.SimpleDateFormat)5 DatasetBean (org.akaza.openclinica.bean.extract.DatasetBean)5 DatasetDAO (org.akaza.openclinica.dao.extract.DatasetDAO)5 TriggerKey (org.quartz.TriggerKey)5 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)4 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)4