use of org.springframework.scheduling.annotation.Scheduled in project NabAlive by jcheype.
the class ApplicationScheduler method scheduled.
@Scheduled(cron = "0 * * * * *")
public void scheduled() {
logger.debug("scheduled");
Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
int hour = cal.get(Calendar.HOUR_OF_DAY);
int minute = cal.get(Calendar.MINUTE);
int day = cal.get(Calendar.DAY_OF_WEEK);
String scheduleKey = String.format("%02d:%02d-%d", hour, minute, day);
logger.debug("scheduleKey: {}", scheduleKey);
Query<Nabaztag> queryWakeUp = nabaztagDAO.createQuery().filter("wakeup", scheduleKey);
sendToAll(queryWakeUp, new SleepPacket(SleepPacket.Action.WakeUp));
Query<Nabaztag> querySleep = nabaztagDAO.createQuery().filter("sleep", scheduleKey);
sendToAll(querySleep, new SleepPacket(SleepPacket.Action.Sleep));
}
use of org.springframework.scheduling.annotation.Scheduled in project new-cloud by xie-summer.
the class ScheduleTriggerServiceImpl method refreshTrigger.
/**
* 定时刷新扫描配置表
*/
@Scheduled(fixedRate = 1000 * 30)
@Override
public void refreshTrigger() {
try {
List<ScheduleTrigger> jobList = scheduleTriggerMapper.selectAll();
if (null != jobList && jobList.size() > 0) {
for (ScheduleTrigger scheduleJob : jobList) {
String status = scheduleJob.getStatus();
TriggerKey triggerKey = TriggerKey.triggerKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey);
// 说明本条任务还没有添加到quartz中
if (null == trigger) {
if (STATUS.equals(status)) {
continue;
}
JobDetail jobDetail = null;
try {
// 创建JobDetail(数据库中job_name存的任务全路径,这里就可以动态的把任务注入到JobDetail中)
jobDetail = JobBuilder.newJob((Class<? extends Job>) Class.forName(scheduleJob.getJobName())).withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroup()).build();
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(scheduleJob.getCron());
trigger = TriggerBuilder.newTrigger().withIdentity(scheduleJob.getJobName(), scheduleJob.getJobGroup()).withSchedule(scheduleBuilder).build();
scheduler.scheduleJob(jobDetail, trigger);
} catch (ClassNotFoundException e) {
}
} else {
// 如果是禁用,从quartz中删除这条任务
if (STATUS.equals(status)) {
JobKey jobKey = JobKey.jobKey(scheduleJob.getJobName(), scheduleJob.getJobGroup());
scheduler.deleteJob(jobKey);
continue;
}
String searchCron = scheduleJob.getCron();
String currentCron = trigger.getCronExpression();
if (!searchCron.equals(currentCron)) {
// 表达式调度构建器
CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(searchCron);
// 按新的cronExpression表达式重新构建trigger
trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build();
// 按新的trigger重新设置job执行
scheduler.rescheduleJob(triggerKey, trigger);
}
}
}
}
} catch (Exception e) {
logger.error("定时任务每日刷新触发器任务异常,在ScheduleTriggerService的方法refreshTrigger中,异常信息:", e);
}
}
use of org.springframework.scheduling.annotation.Scheduled in project OpenClinica by OpenClinica.
the class JobTriggerService method hourlyJobTrigger.
// @Scheduled(cron = "0 0/2 * * * ?") // trigger every 2 minutes
// @Scheduled(cron = "0 0/1 * * * ?") // trigger every minute
// trigger every hour
@Scheduled(cron = "0 0 0/1 * * ?")
public void hourlyJobTrigger() throws NumberFormatException, ParseException {
try {
logger.info("Beginning scheduled rule run. The time is now " + currentDateFormat.format(new Date()));
triggerJob();
logger.info("Completed scheduled rule run.");
} catch (Exception e) {
logger.error(e.getMessage());
logger.error(ExceptionUtils.getStackTrace(e));
throw e;
}
}
use of org.springframework.scheduling.annotation.Scheduled in project CzechIdMng by bcvsolutions.
the class DefaultAttachmentManager method purgeTemp.
/**
* Purge old temporary files and attachments once per day.
* Temporary files older than configured ttl will be purged.
* Temporary uploaded attachments older than configured ttl will be purged.
*
* @return purged files count
*/
// once per day
@Scheduled(fixedDelay = 86400000)
public void purgeTemp() {
int purgedFiles = 0;
long ttl = attachmentConfiguration.getTempTtl();
if (ttl == 0) {
LOG.warn("Removing old temporary files is disabled. Configure property [{}] - time to live in milliseconds (greater than zero).", AttachmentConfiguration.PROPERTY_TEMP_TTL);
return;
}
//
// purge older temporary files than purge time
long purgeTime = System.currentTimeMillis() - ttl;
File temp = new File(getTempPath());
if (temp.isDirectory()) {
File[] files = temp.listFiles();
if (files != null) {
for (File f : files) {
try {
if (f.getName().endsWith("." + DEFAULT_TEMP_FILE_EXTENSION) && f.lastModified() < purgeTime) {
f.delete();
purgedFiles++;
}
} catch (Exception ex) {
LOG.error("Removing old temporary [.{}] file [{}] failed", DEFAULT_TEMP_FILE_EXTENSION, f.getName(), ex);
}
}
}
}
//
// purge temporary attachments
IdmAttachmentFilter filter = new IdmAttachmentFilter();
filter.setOwnerType(TEMPORARY_ATTACHMENT_OWNER_TYPE);
filter.setCreatedBefore(ZonedDateTime.now().minus(ttl, ChronoField.MILLI_OF_DAY.getBaseUnit()));
for (IdmAttachmentDto attachment : find(filter, null)) {
delete(attachment);
purgedFiles++;
}
//
LOG.debug("Temporary files were purged [{}]", purgedFiles);
}
use of org.springframework.scheduling.annotation.Scheduled in project anton-pavlovich-bot by wyvie.
the class MessageReader method readMessages.
@Scheduled(fixedDelay = 200)
public void readMessages() {
GetUpdates getUpdates = new GetUpdates().limit(telegramProperties.getUpdateLimit()).offset(lastOffset).timeout(0);
GetUpdatesResponse response = telegramBot.execute(getUpdates);
List<Update> updates = response.updates();
updates.forEach(update -> {
lastOffset = update.updateId() + 1;
Message message = update.message();
if (message != null && message.from() != null && bannedUsers.contains(message.from().id())) {
logger.debug("Message ignored from user " + message.from().id());
persistUser(message.from());
return;
}
if (message != null && message.text() != null) {
logger.debug("Got message '" + message.text() + "' from chat_id " + message.chat().id());
persistUser(message.from());
if (validateCommmand(message))
commandProcessor.processCommand(message);
else {
String messageText;
messageText = message.text().trim();
if (messageText.startsWith("+") || messageText.startsWith("-") || emojiHelper.isThumbsUp(messageText) || emojiHelper.isThumbsDown(messageText))
commandProcessor.processKarma(message);
}
lastOffset = update.updateId() + 1;
}
if (message != null && message.sticker() != null) {
String emoji = message.sticker().emoji();
if (emojiHelper.isThumbsDown(emoji) || emojiHelper.isThumbsUp(emoji)) {
commandProcessor.processKarma(message);
}
}
});
}
Aggregations