commit
d0f5c1f6ee
@ -0,0 +1,20 @@
|
||||
package com.xxl.job.admin.core.alarm;
|
||||
|
||||
import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||
import com.xxl.job.admin.core.model.XxlJobLog;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2020-01-19
|
||||
*/
|
||||
public interface JobAlarm {
|
||||
|
||||
/**
|
||||
* job alarm
|
||||
*
|
||||
* @param info
|
||||
* @param jobLog
|
||||
* @return
|
||||
*/
|
||||
public boolean doAlarm(XxlJobInfo info, XxlJobLog jobLog);
|
||||
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.xxl.job.admin.core.alarm;
|
||||
|
||||
import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||
import com.xxl.job.admin.core.model.XxlJobLog;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class JobAlarmer implements ApplicationContextAware, InitializingBean {
|
||||
private static Logger logger = LoggerFactory.getLogger(JobAlarmer.class);
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
private List<JobAlarm> jobAlarmList;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Map<String, JobAlarm> serviceBeanMap = applicationContext.getBeansOfType(JobAlarm.class);
|
||||
if (serviceBeanMap != null && serviceBeanMap.size() > 0) {
|
||||
jobAlarmList = new ArrayList<JobAlarm>(serviceBeanMap.values());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* job alarm
|
||||
*
|
||||
* @param info
|
||||
* @param jobLog
|
||||
* @return
|
||||
*/
|
||||
public boolean alarm(XxlJobInfo info, XxlJobLog jobLog) {
|
||||
|
||||
boolean result = false;
|
||||
if (jobAlarmList!=null && jobAlarmList.size()>0) {
|
||||
result = true; // success means all-success
|
||||
for (JobAlarm alarm: jobAlarmList) {
|
||||
boolean resultItem = false;
|
||||
try {
|
||||
resultItem = alarm.doAlarm(info, jobLog);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
if (!resultItem) {
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,24 +1,24 @@
|
||||
package com.xxl.job.core.handler.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* annotation for job handler
|
||||
*
|
||||
* will be replaced by {@link com.xxl.job.core.handler.annotation.XxlJob}
|
||||
*
|
||||
* @author 2016-5-17 21:06:49
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@Deprecated
|
||||
public @interface JobHandler {
|
||||
|
||||
String value() default "";
|
||||
|
||||
}
|
||||
//package com.xxl.job.core.handler.annotation;
|
||||
//
|
||||
//import java.lang.annotation.ElementType;
|
||||
//import java.lang.annotation.Inherited;
|
||||
//import java.lang.annotation.Retention;
|
||||
//import java.lang.annotation.RetentionPolicy;
|
||||
//import java.lang.annotation.Target;
|
||||
//
|
||||
///**
|
||||
// * annotation for job handler
|
||||
// *
|
||||
// * will be replaced by {@link com.xxl.job.core.handler.annotation.XxlJob}
|
||||
// *
|
||||
// * @author 2016-5-17 21:06:49
|
||||
// */
|
||||
//@Target({ElementType.TYPE})
|
||||
//@Retention(RetentionPolicy.RUNTIME)
|
||||
//@Inherited
|
||||
//@Deprecated
|
||||
//public @interface JobHandler {
|
||||
//
|
||||
// String value();
|
||||
//
|
||||
//}
|
||||
|
Loading…
Reference in new issue