Search in sources :

Example 61 with Trigger

use of org.quartz.Trigger in project pinot by linkedin.

the class AlertJobScheduler method runAdHoc.

public void runAdHoc(Long id, DateTime windowStartTime, DateTime windowEndTime) {
    EmailConfigurationDTO alertConfig = emailConfigurationDAO.findById(id);
    if (alertConfig == null) {
        throw new IllegalArgumentException("No alert config with id " + id);
    }
    String triggerKey = String.format("alert_adhoc_trigger_%d", id);
    Trigger trigger = TriggerBuilder.newTrigger().withIdentity(triggerKey).startNow().build();
    String jobKey = "adhoc_" + getJobKey(id);
    JobDetail job = JobBuilder.newJob(AlertJobRunner.class).withIdentity(jobKey).build();
    AlertJobContext alertJobContext = new AlertJobContext();
    alertJobContext.setJobDAO(anomalyJobDAO);
    alertJobContext.setTaskDAO(anomalyTaskDAO);
    alertJobContext.setEmailConfigurationDAO(emailConfigurationDAO);
    alertJobContext.setAlertConfigId(id);
    alertJobContext.setJobName(jobKey);
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_CONTEXT, alertJobContext);
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_MONITORING_WINDOW_START_TIME, windowStartTime);
    job.getJobDataMap().put(AlertJobRunner.ALERT_JOB_MONITORING_WINDOW_END_TIME, windowEndTime);
    try {
        quartzScheduler.scheduleJob(job, trigger);
    } catch (SchedulerException e) {
        LOG.error("Exception while scheduling job", e);
    }
    LOG.info("Started {}: {}", jobKey, alertConfig);
}
Also used : JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) SchedulerException(org.quartz.SchedulerException) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)

Example 62 with Trigger

use of org.quartz.Trigger in project elastic-job by dangdangdotcom.

the class RegisteredJobStatisticJobTest method assertBuildTrigger.

@Test
public void assertBuildTrigger() throws SchedulerException {
    Trigger trigger = registeredJobStatisticJob.buildTrigger();
    assertThat(trigger.getKey().getName(), is(RegisteredJobStatisticJob.class.getSimpleName() + "Trigger"));
}
Also used : Trigger(org.quartz.Trigger) Test(org.junit.Test)

Example 63 with Trigger

use of org.quartz.Trigger in project elastic-job by dangdangdotcom.

the class JobScheduleController method getNextFireTime.

/**
     * 获取下次作业触发时间.
     * 
     * @return 下次作业触发时间
     */
public Date getNextFireTime() {
    List<? extends Trigger> triggers;
    try {
        triggers = scheduler.getTriggersOfJob(jobDetail.getKey());
    } catch (final SchedulerException ex) {
        return null;
    }
    Date result = null;
    for (Trigger each : triggers) {
        Date nextFireTime = each.getNextFireTime();
        if (null == nextFireTime) {
            continue;
        }
        if (null == result) {
            result = nextFireTime;
        } else if (nextFireTime.getTime() < result.getTime()) {
            result = nextFireTime;
        }
    }
    return result;
}
Also used : SchedulerException(org.quartz.SchedulerException) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) Date(java.util.Date)

Example 64 with Trigger

use of org.quartz.Trigger in project openhab1-addons by openhab.

the class GCalEventDownloader method createJobInfo.

/**
     * Creates a detailed description of a <code>job</code> for logging purpose.
     *
     * @param job the job to create a detailed description for
     * @return a detailed description of the new <code>job</code>
     */
private String createJobInfo(Event event, JobDetail job) {
    if (job == null) {
        return "SchedulerJob [null]";
    }
    StringBuffer sb = new StringBuffer();
    sb.append("SchedulerJob [jobKey=").append(job.getKey().getName());
    sb.append(", jobGroup=").append(job.getKey().getGroup());
    try {
        List<? extends Trigger> triggers = scheduler.getTriggersOfJob(job.getKey());
        sb.append(", ").append(triggers.size()).append(" triggers=[");
        int maxTriggerLogs = 24;
        for (int triggerIndex = 0; triggerIndex < triggers.size() && triggerIndex < maxTriggerLogs; triggerIndex++) {
            Trigger trigger = triggers.get(triggerIndex);
            sb.append(trigger.getStartTime());
            if (triggerIndex < triggers.size() - 1 && triggerIndex < maxTriggerLogs - 1) {
                sb.append(", ");
            }
        }
        if (triggers.size() >= maxTriggerLogs) {
            sb.append(" and ").append(triggers.size() - maxTriggerLogs).append(" more ...");
        }
        if (triggers.size() == 0) {
            sb.append("there are no triggers - probably the event lies in the past");
        }
    } catch (SchedulerException e) {
    }
    sb.append("], content=").append(event.getDescription());
    return sb.toString();
}
Also used : Trigger(org.quartz.Trigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) SchedulerException(org.quartz.SchedulerException)

Example 65 with Trigger

use of org.quartz.Trigger in project openhab1-addons by openhab.

the class AbstractDatagramChannelBinding method internalReceiveCommand.

/**
     * {@inheritDoc}
     */
@Override
protected void internalReceiveCommand(String itemName, Command command) {
    P provider = findFirstMatchingBindingProvider(itemName);
    if (provider == null) {
        logger.warn("cannot find matching binding provider [itemName={}, command={}]", itemName, command);
        return;
    }
    if (command != null) {
        List<Command> commands = provider.getQualifiedCommands(itemName, command);
        for (Command someCommand : commands) {
            Channel theChannel = null;
            if (useAddressMask && (provider.getHost(itemName, someCommand).equals("*") || provider.getPortAsString(itemName, someCommand).equals("*"))) {
                theChannel = channels.get(itemName, someCommand, provider.getDirection(itemName, someCommand), provider.getHost(itemName, someCommand), provider.getPortAsString(itemName, someCommand));
            } else {
                theChannel = channels.get(itemName, someCommand, provider.getDirection(itemName, someCommand), new InetSocketAddress(provider.getHost(itemName, someCommand), provider.getPort(itemName, someCommand)));
            }
            DatagramChannel theDatagramChannel = null;
            if (theChannel != null) {
                theDatagramChannel = theChannel.channel;
            }
            if (theDatagramChannel != null) {
                boolean result = internalReceiveChanneledCommand(itemName, someCommand, theChannel, command.toString());
                if (!theDatagramChannel.isConnected() && theDatagramChannel != listenerChannel) {
                    logger.warn("The channel for {} has a connection problem. Data will queued to the new channel when it is successfully set up.", theChannel.remote);
                    Scheduler scheduler = null;
                    try {
                        scheduler = StdSchedulerFactory.getDefaultScheduler();
                    } catch (SchedulerException e1) {
                        logger.error("An exception occurred while getting the Quartz scheduler: {}", e1.getMessage());
                    }
                    JobDataMap map = new JobDataMap();
                    map.put("Channel", theChannel);
                    map.put("Binding", this);
                    JobDetail job = newJob(ReconnectJob.class).withIdentity(Integer.toHexString(hashCode()) + "-Reconnect-" + Long.toString(System.currentTimeMillis()), this.toString()).usingJobData(map).build();
                    Trigger trigger = newTrigger().withIdentity(Integer.toHexString(hashCode()) + "-Reconnect-" + Long.toString(System.currentTimeMillis()), this.toString()).startNow().build();
                    try {
                        if (job != null && trigger != null) {
                            if (!theChannel.isReconnecting) {
                                theChannel.isReconnecting = true;
                                scheduler.scheduleJob(job, trigger);
                            }
                        }
                    } catch (SchedulerException e) {
                        logger.error("An exception occurred while scheduling a job with the Quartz Scheduler {}", e.getMessage());
                    }
                }
                if (result) {
                    List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName, someCommand);
                    State newState = createStateFromString(stateTypeList, command.toString());
                    if (newState != null) {
                        eventPublisher.postUpdate(itemName, newState);
                    }
                }
            } else {
                logger.error("there is no channel that services [itemName={}, command={}]", itemName, command);
            }
        }
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) SchedulerException(org.quartz.SchedulerException) InetSocketAddress(java.net.InetSocketAddress) Scheduler(org.quartz.Scheduler) DatagramChannel(java.nio.channels.DatagramChannel) SocketChannel(java.nio.channels.SocketChannel) DatagramChannel(java.nio.channels.DatagramChannel) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) Command(org.openhab.core.types.Command) State(org.openhab.core.types.State)

Aggregations

Trigger (org.quartz.Trigger)104 JobDetail (org.quartz.JobDetail)51 SchedulerException (org.quartz.SchedulerException)40 CronTrigger (org.quartz.CronTrigger)29 Test (org.junit.Test)23 Scheduler (org.quartz.Scheduler)22 JobDataMap (org.quartz.JobDataMap)21 SimpleTrigger (org.quartz.SimpleTrigger)20 TriggerKey (org.quartz.TriggerKey)20 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)19 JobKey (org.quartz.JobKey)16 ArrayList (java.util.ArrayList)13 Date (java.util.Date)12 List (java.util.List)5 Command (org.openhab.core.types.Command)5 InetSocketAddress (java.net.InetSocketAddress)4 SocketChannel (java.nio.channels.SocketChannel)4 ParseException (java.text.ParseException)4 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)4 ProtoTrigger (co.cask.cdap.proto.ProtoTrigger)3