吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1063|回复: 2
收起左侧

[Java 原创] xxL-job 失败消息提醒

[复制链接]
我是白小白 发表于 2023-1-13 11:08


过年了 回老家 担心任务失败 不知道

xxljib 查询任务  执行日志  还有那个页面的报表

写个定时任务 定时查 错误 任务 发消息提醒









[Java] 纯文本查看 复制代码
public static void main(String[] args) {

        XxlJobUtils xxlJobUtils = new XxlJobUtils("","","");

        //查询所有job任务信息
        xxlJobUtils.getJobInfo();
        
        //查询执行器信息
        xxlJobUtils.getJobgroup("","");


        //查询时间段内报表  startDate  endDate
        xxlJobUtils.getChartinfoUrlhartInfo("","");

        //查询job执行日志
        xxlJobUtils.getJobLog("","","","","");

    }


[url=][/url][url=][/url][url=][/url]

刚工作一年的 java程序员 平时就 crud

如果有大佬看到bug 或者可以优化的地方
可以帮忙指出来 不胜感激

[Java] 纯文本查看 复制代码
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";

    private  static 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;


    private  static 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(";")[0];
        } 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");




    public  String 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);
        }
    }


    public  String 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);
        }
    }


    //
    public  String 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);
        }
    }



    public  String 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);
        }
    }



}

图片.png
0.png
屏幕截图 2023-01-13 104550.png
1.png

免费评分

参与人数 2吾爱币 +8 热心值 +2 收起 理由
gdhgn + 1 + 1 我很赞同!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

梦溪笔谈2048 发表于 2023-1-18 20:05
xxl-job原本不就有任务失败邮件提醒???也有可视化界面呀
 楼主| 我是白小白 发表于 2023-1-19 15:23
梦溪笔谈2048 发表于 2023-1-18 20:05
xxl-job原本不就有任务失败邮件提醒???也有可视化界面呀

害 可视化页面 是有的 但是过年回家  不太方便看
邮件一般都不咋看 通过接口直接推部门群
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-3-29 03:12

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表