提交 | 用户 | 时间
|
e7c126
|
1 |
package com.xxl.job.admin.core.alarm; |
H |
2 |
|
|
3 |
import com.xxl.job.admin.core.model.XxlJobInfo; |
|
4 |
import com.xxl.job.admin.core.model.XxlJobLog; |
|
5 |
import org.slf4j.Logger; |
|
6 |
import org.slf4j.LoggerFactory; |
|
7 |
import org.springframework.beans.BeansException; |
|
8 |
import org.springframework.beans.factory.InitializingBean; |
|
9 |
import org.springframework.context.ApplicationContext; |
|
10 |
import org.springframework.context.ApplicationContextAware; |
|
11 |
import org.springframework.stereotype.Component; |
|
12 |
|
|
13 |
import java.util.ArrayList; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
|
16 |
|
|
17 |
@Component |
|
18 |
public class JobAlarmer implements ApplicationContextAware, InitializingBean { |
|
19 |
private static Logger logger = LoggerFactory.getLogger(JobAlarmer.class); |
|
20 |
|
|
21 |
private ApplicationContext applicationContext; |
|
22 |
private List<JobAlarm> jobAlarmList; |
|
23 |
|
|
24 |
@Override |
|
25 |
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
|
26 |
this.applicationContext = applicationContext; |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
public void afterPropertiesSet() throws Exception { |
|
31 |
Map<String, JobAlarm> serviceBeanMap = applicationContext.getBeansOfType(JobAlarm.class); |
|
32 |
if (serviceBeanMap != null && serviceBeanMap.size() > 0) { |
|
33 |
jobAlarmList = new ArrayList<JobAlarm>(serviceBeanMap.values()); |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
/** |
|
38 |
* job alarm |
|
39 |
* |
|
40 |
* @param info |
|
41 |
* @param jobLog |
|
42 |
* @return |
|
43 |
*/ |
|
44 |
public boolean alarm(XxlJobInfo info, XxlJobLog jobLog) { |
|
45 |
|
|
46 |
boolean result = false; |
|
47 |
if (jobAlarmList!=null && jobAlarmList.size()>0) { |
|
48 |
result = true; // success means all-success |
|
49 |
for (JobAlarm alarm: jobAlarmList) { |
|
50 |
boolean resultItem = false; |
|
51 |
try { |
|
52 |
resultItem = alarm.doAlarm(info, jobLog); |
|
53 |
} catch (Exception e) { |
|
54 |
logger.error(e.getMessage(), e); |
|
55 |
} |
|
56 |
if (!resultItem) { |
|
57 |
result = false; |
|
58 |
} |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
return result; |
|
63 |
} |
|
64 |
|
|
65 |
} |