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);
}
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"));
}
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;
}
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();
}
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);
}
}
}
}
Aggregations