parent
3604b35483
commit
eacf4f3618
@ -1,11 +1,9 @@
|
||||
FROM openjdk:8-jre-slim
|
||||
MAINTAINER xuxueli
|
||||
|
||||
ENV PARAMS=""
|
||||
FROM registry.cn-hangzhou.aliyuncs.com/bimface_common/centos7-jdk8:v2_u181
|
||||
MAINTAINER BIMFACE
|
||||
|
||||
ENV TZ=PRC
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
ADD target/xxl-job-admin-*.jar /app.jar
|
||||
ADD target/xxl-job-admin.jar /app.jar
|
||||
|
||||
ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]
|
||||
ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar "]
|
@ -0,0 +1,39 @@
|
||||
package com.xxl.job.admin.core.alarm;
|
||||
|
||||
import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
||||
import com.xxl.job.admin.core.util.I18nUtil;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public abstract class AbstractJobAlarm {
|
||||
|
||||
protected String appendEnv(String input) {
|
||||
if (StringUtils.hasText(XxlJobAdminConfig.getAdminConfig().getEnv())) {
|
||||
return input + "(" + XxlJobAdminConfig.getAdminConfig().getEnv() + ")";
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
/**
|
||||
* load email job alarm template
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected String loadAlarmTemplate(int triggerCode) {
|
||||
return "<font color=\"warning\">" + appendEnv(I18nUtil.getString("jobconf_monitor_detail")) + "</font>,请相关同事注意。\n> "
|
||||
+ I18nUtil.getString("jobinfo_field_jobgroup") + ":<font color=\"comment\">{0}</font>\n> "
|
||||
+ I18nUtil.getString("jobinfo_field_id") + ":<font color=\"comment\">{1}</font>\n> "
|
||||
+ I18nUtil.getString("jobinfo_field_jobdesc") + ":<font color=\"comment\">{2}</font>\n> "
|
||||
+ I18nUtil.getString("jobconf_monitor_alarm_title") + ":<font color=\"comment\">" + getAlarmType(triggerCode) + "</font>\n> "
|
||||
+ I18nUtil.getString("jobconf_monitor_alarm_content") + ":<font color=\"comment\">{3}</font>\n> ";
|
||||
}
|
||||
|
||||
protected String getAlarmType(int triggerCode) {
|
||||
if (triggerCode == 200) {
|
||||
// 触发成功 即为 执行失败
|
||||
return I18nUtil.getString("jobconf_monitor_alarm_execute_fail_type");
|
||||
}
|
||||
// 触发不成功, 为调度失败
|
||||
return I18nUtil.getString("jobconf_monitor_alarm_type");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.xxl.job.admin.core.alarm.impl;
|
||||
|
||||
import com.xxl.job.admin.core.alarm.AbstractJobAlarm;
|
||||
import com.xxl.job.admin.core.alarm.JobAlarm;
|
||||
import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
|
||||
import com.xxl.job.admin.core.model.XxlJobGroup;
|
||||
import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||
import com.xxl.job.admin.core.model.XxlJobLog;
|
||||
import com.xxl.job.core.biz.model.ReturnT;
|
||||
import com.xxl.job.core.util.XxlJobRemotingUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Order(1)
|
||||
@Component
|
||||
public class WechatJobAlarm extends AbstractJobAlarm implements JobAlarm {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(WechatJobAlarm.class);
|
||||
|
||||
@Override
|
||||
public boolean doAlarm(XxlJobInfo info, XxlJobLog jobLog) {
|
||||
boolean alarmResult = true;
|
||||
|
||||
// send monitor email
|
||||
if (info != null && XxlJobAdminConfig.getAdminConfig().isEnableWeChatAlarm() && StringUtils.hasText(XxlJobAdminConfig.getAdminConfig().getWechatHook())) {
|
||||
|
||||
// alarmContent
|
||||
String alarmContent = "Alarm Job LogId=" + jobLog.getId();
|
||||
if (jobLog.getTriggerCode() != ReturnT.SUCCESS_CODE) {
|
||||
alarmContent += "\nTriggerMsg=" + jobLog.getTriggerMsg();
|
||||
}
|
||||
if (jobLog.getHandleCode() > 0 && jobLog.getHandleCode() != ReturnT.SUCCESS_CODE) {
|
||||
alarmContent += "\nHandleCode=" + jobLog.getHandleMsg();
|
||||
}
|
||||
|
||||
// email info
|
||||
XxlJobGroup group = XxlJobAdminConfig.getAdminConfig().getXxlJobGroupDao().load(info.getJobGroup());
|
||||
String s = alarmContent.replaceAll("<br><br>", "\n")
|
||||
.replaceAll("<br>", "\n")
|
||||
.replaceAll("<span style=\"color:#00c0ef;\" >", "")
|
||||
.replaceAll("</span>", "");
|
||||
String result = Arrays.asList(s.split("\n")).stream().map(input -> "<font color=\"comment\">" + input + "</font>").collect(Collectors.joining("\n"));
|
||||
String content = MessageFormat.format(loadAlarmTemplate(jobLog.getTriggerCode()),
|
||||
group != null ? group.getTitle() : "null",
|
||||
info.getId(),
|
||||
info.getJobDesc(),
|
||||
result);
|
||||
|
||||
// make mail
|
||||
try {
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("msgtype", "markdown");
|
||||
Map<String, Object> markdownContent = new HashMap<>();
|
||||
markdownContent.put("content", content);
|
||||
body.put("markdown", markdownContent);
|
||||
XxlJobRemotingUtil.postBody(XxlJobAdminConfig.getAdminConfig().getWechatHook(), null, 5, body, String.class);
|
||||
} catch (Exception e) {
|
||||
logger.error(">>>>>>>>>>> xxl-job, job fail alarm wechat send error, JobLogId:{}", jobLog.getId(), e);
|
||||
alarmResult = false;
|
||||
}
|
||||
}
|
||||
|
||||
return alarmResult;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job</artifactId>
|
||||
<version>2.3.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>xxl-job-executor-samples</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>xxl-job-executor-sample-frameless</module>
|
||||
<module>xxl-job-executor-sample-springboot</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-executor-samples</artifactId>
|
||||
<version>2.3.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>xxl-job-executor-sample-frameless</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>Example executor project for spring boot.</description>
|
||||
<url>https://www.xuxueli.com/</url>
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- slf4j -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j-api.version}</version>
|
||||
</dependency>
|
||||
<!-- junit -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- xxl-job-core -->
|
||||
<dependency>
|
||||
<groupId>com.xuxueli</groupId>
|
||||
<artifactId>xxl-job-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
@ -1,38 +0,0 @@
|
||||
package com.xxl.job.executor.sample.frameless;
|
||||
|
||||
import com.xxl.job.executor.sample.frameless.config.FrameLessXxlJobConfig;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2018-10-31 19:05:43
|
||||
*/
|
||||
public class FramelessApplication {
|
||||
private static Logger logger = LoggerFactory.getLogger(FramelessApplication.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
// start
|
||||
FrameLessXxlJobConfig.getInstance().initXxlJobExecutor();
|
||||
|
||||
// Blocks until interrupted
|
||||
while (true) {
|
||||
try {
|
||||
TimeUnit.HOURS.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
} finally {
|
||||
// destroy
|
||||
FrameLessXxlJobConfig.getInstance().destroyXxlJobExecutor();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
package com.xxl.job.executor.sample.frameless.config;
|
||||
|
||||
import com.xxl.job.executor.sample.frameless.jobhandler.SampleXxlJob;
|
||||
import com.xxl.job.core.executor.impl.XxlJobSimpleExecutor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2018-10-31 19:05:43
|
||||
*/
|
||||
public class FrameLessXxlJobConfig {
|
||||
private static Logger logger = LoggerFactory.getLogger(FrameLessXxlJobConfig.class);
|
||||
|
||||
|
||||
private static FrameLessXxlJobConfig instance = new FrameLessXxlJobConfig();
|
||||
public static FrameLessXxlJobConfig getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private XxlJobSimpleExecutor xxlJobExecutor = null;
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
public void initXxlJobExecutor() {
|
||||
|
||||
// load executor prop
|
||||
Properties xxlJobProp = loadProperties("xxl-job-executor.properties");
|
||||
|
||||
// init executor
|
||||
xxlJobExecutor = new XxlJobSimpleExecutor();
|
||||
xxlJobExecutor.setAdminAddresses(xxlJobProp.getProperty("xxl.job.admin.addresses"));
|
||||
xxlJobExecutor.setAccessToken(xxlJobProp.getProperty("xxl.job.accessToken"));
|
||||
xxlJobExecutor.setAppname(xxlJobProp.getProperty("xxl.job.executor.appname"));
|
||||
xxlJobExecutor.setAddress(xxlJobProp.getProperty("xxl.job.executor.address"));
|
||||
xxlJobExecutor.setIp(xxlJobProp.getProperty("xxl.job.executor.ip"));
|
||||
xxlJobExecutor.setPort(Integer.valueOf(xxlJobProp.getProperty("xxl.job.executor.port")));
|
||||
xxlJobExecutor.setLogPath(xxlJobProp.getProperty("xxl.job.executor.logpath"));
|
||||
xxlJobExecutor.setLogRetentionDays(Integer.valueOf(xxlJobProp.getProperty("xxl.job.executor.logretentiondays")));
|
||||
|
||||
// registry job bean
|
||||
xxlJobExecutor.setXxlJobBeanList(Arrays.asList(new SampleXxlJob()));
|
||||
|
||||
// start executor
|
||||
try {
|
||||
xxlJobExecutor.start();
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* destroy
|
||||
*/
|
||||
public void destroyXxlJobExecutor() {
|
||||
if (xxlJobExecutor != null) {
|
||||
xxlJobExecutor.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Properties loadProperties(String propertyFileName) {
|
||||
InputStreamReader in = null;
|
||||
try {
|
||||
ClassLoader loder = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
in = new InputStreamReader(loder.getResourceAsStream(propertyFileName), "UTF-8");;
|
||||
if (in != null) {
|
||||
Properties prop = new Properties();
|
||||
prop.load(in);
|
||||
return prop;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("load {} error!", propertyFileName);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
logger.error("close {} error!", propertyFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">
|
||||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" threshold="null" debug="null">
|
||||
|
||||
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
|
||||
<param name="Target" value="System.out" />
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-frameless [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
|
||||
<param name="file" value="/data/applogs/xxl-job/xxl-job-executor-sample-frameless.log"/>
|
||||
<param name="append" value="true"/>
|
||||
<param name="encoding" value="UTF-8"/>
|
||||
<layout class="org.apache.log4j.PatternLayout">
|
||||
<param name="ConversionPattern" value="%-d{yyyy-MM-dd HH:mm:ss} xxl-job-executor-sample-frameless [%c]-[%t]-[%M]-[%L]-[%p] %m%n"/>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="CONSOLE" />
|
||||
<appender-ref ref="FILE" />
|
||||
</root>
|
||||
|
||||
</log4j:configuration>
|
@ -1,17 +0,0 @@
|
||||
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
|
||||
|
||||
### xxl-job, access token
|
||||
xxl.job.accessToken=
|
||||
|
||||
### xxl-job executor appname
|
||||
xxl.job.executor.appname=xxl-job-executor-sample
|
||||
### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
|
||||
xxl.job.executor.address=
|
||||
### xxl-job executor server-info
|
||||
xxl.job.executor.ip=
|
||||
xxl.job.executor.port=9998
|
||||
### xxl-job executor log-path
|
||||
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
|
||||
### xxl-job executor log-retention-days
|
||||
xxl.job.executor.logretentiondays=30
|
@ -1,12 +0,0 @@
|
||||
package com.xxl.job.executor.sample.frameless.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class FramelessApplicationTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
System.out.println("111");
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
FROM openjdk:8-jre-slim
|
||||
MAINTAINER xuxueli
|
||||
|
||||
ENV PARAMS=""
|
||||
|
||||
ENV TZ=PRC
|
||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||
|
||||
ADD target/xxl-job-executor-sample-springboot-*.jar /app.jar
|
||||
|
||||
ENTRYPOINT ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"]
|
@ -1,16 +0,0 @@
|
||||
package com.xxl.job.executor;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2018-10-28 00:38:13
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class XxlJobExecutorApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(XxlJobExecutorApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
//package com.xxl.job.executor.mvc.controller;
|
||||
//
|
||||
//import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
//import org.springframework.stereotype.Controller;
|
||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
||||
//import org.springframework.web.bind.annotation.ResponseBody;
|
||||
//
|
||||
//@Controller
|
||||
//@EnableAutoConfiguration
|
||||
//public class IndexController {
|
||||
//
|
||||
// @RequestMapping("/")
|
||||
// @ResponseBody
|
||||
// String index() {
|
||||
// return "xxl job executor running.";
|
||||
// }
|
||||
//
|
||||
//}
|
@ -1,26 +0,0 @@
|
||||
# web port
|
||||
server.port=8081
|
||||
# no web
|
||||
#spring.main.web-environment=false
|
||||
|
||||
# log config
|
||||
logging.config=classpath:logback.xml
|
||||
|
||||
|
||||
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
|
||||
|
||||
### xxl-job, access token
|
||||
xxl.job.accessToken=
|
||||
|
||||
### xxl-job executor appname
|
||||
xxl.job.executor.appname=xxl-job-executor-sample
|
||||
### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
|
||||
xxl.job.executor.address=
|
||||
### xxl-job executor server-info
|
||||
xxl.job.executor.ip=
|
||||
xxl.job.executor.port=9999
|
||||
### xxl-job executor log-path
|
||||
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
|
||||
### xxl-job executor log-retention-days
|
||||
xxl.job.executor.logretentiondays=30
|
@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration debug="false" scan="true" scanPeriod="1 seconds">
|
||||
|
||||
<contextName>logback</contextName>
|
||||
<property name="log.path" value="/data/applogs/xxl-job/xxl-job-executor-sample-springboot.log"/>
|
||||
|
||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>
|
||||
</rollingPolicy>
|
||||
<encoder>
|
||||
<pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="console"/>
|
||||
<appender-ref ref="file"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
@ -1,14 +0,0 @@
|
||||
package com.xxl.job.executor.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class XxlJobExecutorExampleBootApplicationTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
System.out.println(11);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue