xxL-job 失败消息提醒
过年了 回老家 担心任务失败 不知道
https://static.52pojie.cn/static/image/smiley/default/4.gif xxljib 查询任务执行日志还有那个页面的报表
写个定时任务 定时查 错误 任务 发消息提醒
public static void main(String[] args) {
XxlJobUtils xxlJobUtils = new XxlJobUtils("","","");
//查询所有job任务信息
xxlJobUtils.getJobInfo();
//查询执行器信息
xxlJobUtils.getJobgroup("","");
//查询时间段内报表startDateendDate
xxlJobUtils.getChartinfoUrlhartInfo("","");
//查询job执行日志
xxlJobUtils.getJobLog("","","","","");
}
https://attach.52pojie.cn//forum/202301/13/104558czpaculfcyv9000p.png?lhttps://attach.52pojie.cn//forum/202301/13/110358mydzrwjwmwzq6oww.png?lhttps://attach.52pojie.cn//forum/202301/13/110401hcggapvyu2pngcnc.png?l
刚工作一年的 java程序员 平时就 crud
如果有大佬看到bug 或者可以优化的地方
可以帮忙指出来 不胜感激
package main.java.com.github.kewei1.xxlJob;
import okhttp3.*;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class XxlJobUtils {
private final static OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(60000, TimeUnit.MILLISECONDS)
.readTimeout(60000, TimeUnit.MILLISECONDS)
.build();
private final static String LOGIN_URL = "/xxl-job-admin/login";
private final static String JOBLOG_URL = "/xxl-job-admin/joblog/pageList";
private final static String JOBINFO_URL = "/xxl-job-admin/jobinfo/pageList";
private final static String CHARTINFO_URL = "/xxl-job-admin/chartInfo";
private final static String JOBGROUP_URL = "/xxl-job-admin/jobgroup/pageList";
privatestatic String BASE_URL = "";
private static String USERNAME = "";
private static String PASSWORD = "";
public final static int Faild = 2;
public final static int Success = 1;
public final static int Running = 3;
public final static int ALL = -1;
privatestatic String COOKIE = "";
public XxlJobUtils(String username, String password,String url) {
USERNAME = username;
PASSWORD = password;
BASE_URL = url;
Request request = new Request.Builder()
.url(BASE_URL+LOGIN_URL+"?userName="+ USERNAME+"+&password="+PASSWORD)
.post(body)
.addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001")
.build();
Response response = null;
try {
response = client.newCall(request).execute();
COOKIE = response.headers().get("Set-Cookie").split(";");
} catch (IOException e) {
}
}
private final static MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001") ;
private final static RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001--\r\n\r\n");
publicString getJobLog(int jobGroup, int jobId, int logStatus , int start, int length, String jobStartTime, String jobEndTime) {
Request request = new Request.Builder()
.url(BASE_URL+JOBLOG_URL+"?jobGroup="+jobGroup+"&jobId="+jobId+"&logStatus="+logStatus+"&filterTime="+jobStartTime.replace(" ","+")+"+-+"+jobEndTime.replace(" ","+")+"&start="+start+"&length="+length)
.post(body)
.addHeader("cookie", COOKIE)
.build();
Response response = null;
try {
response = client.newCall(request).execute();
return response.body().string();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
publicString getChartinfoUrlhartInfo(String startDate, String endDate) {
Request request = new Request.Builder()
.url(BASE_URL+CHARTINFO_URL+"?startDate="+startDate.replace(" ","+")+"&endDate="+endDate.replace(" ","+"))
.post(body)
.addHeader("cookie", COOKIE)
.build();
Response response = null;
try {
response = client.newCall(request).execute();
return response.body().string();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
//
publicString getJobgroup(String start, String length) {
Request request = new Request.Builder()
.url(BASE_URL+JOBGROUP_URL+"?start="+start+"&length="+length)
.post(body)
.addHeader("cookie", COOKIE)
.build();
Response response = null;
try {
response = client.newCall(request).execute();
return response.body().string();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
publicString getJobInfo() {
Request request = new Request.Builder()
.url(BASE_URL+JOBINFO_URL+"?triggerStatus=-1&start=0&length=1000&jobGroup=0")
.post(body)
.addHeader("cookie", COOKIE)
.build();
Response response = null;
try {
response = client.newCall(request).execute();
return response.body().string();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
xxl-job原本不就有任务失败邮件提醒???也有可视化界面呀 梦溪笔谈2048 发表于 2023-1-18 20:05
xxl-job原本不就有任务失败邮件提醒???也有可视化界面呀
害 可视化页面 是有的 但是过年回家不太方便看
邮件一般都不咋看 通过接口直接推部门群
页:
[1]