com.xxl.job.core.log.XxlJobFileAppender Java Examples

The following examples show how to use com.xxl.job.core.log.XxlJobFileAppender. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XxlJobExecutor.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {
    // init admin-client
    initAdminBizList(adminAddresses, accessToken);

    // init executor-jobHandlerRepository
    initJobHandlerRepository(applicationContext);

    // init logpath
    XxlJobFileAppender.initLogPath(logPath);

    // init executor-server
    initExecutorServer(port, ip, appName, accessToken);

    // init JobLogFileCleanThread
    JobLogFileCleanThread.getInstance().start(logRetentionDays);
}
 
Example #2
Source File: ScriptJobHandler.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
public ScriptJobHandler(int jobId, long glueUpdatetime, String gluesource, GlueTypeEnum glueType){
    this.jobId = jobId;
    this.glueUpdatetime = glueUpdatetime;
    this.gluesource = gluesource;
    this.glueType = glueType;

    // clean old script file
    File glueSrcPath = new File(XxlJobFileAppender.getGlueSrcPath());
    if (glueSrcPath.exists()) {
        File[] glueSrcFileList = glueSrcPath.listFiles();
        if (glueSrcFileList!=null && glueSrcFileList.length>0) {
            for (File glueSrcFileItem : glueSrcFileList) {
                if (glueSrcFileItem.getName().startsWith(String.valueOf(jobId)+"_")) {
                    glueSrcFileItem.delete();
                }
            }
        }
    }

}
 
Example #3
Source File: ScriptJobHandler.java    From xxl-job with GNU General Public License v3.0 6 votes vote down vote up
public ScriptJobHandler(int jobId, long glueUpdatetime, String gluesource, GlueTypeEnum glueType){
    this.jobId = jobId;
    this.glueUpdatetime = glueUpdatetime;
    this.gluesource = gluesource;
    this.glueType = glueType;

    // clean old script file
    File glueSrcPath = new File(XxlJobFileAppender.getGlueSrcPath());
    if (glueSrcPath.exists()) {
        File[] glueSrcFileList = glueSrcPath.listFiles();
        if (glueSrcFileList!=null && glueSrcFileList.length>0) {
            for (File glueSrcFileItem : glueSrcFileList) {
                if (glueSrcFileItem.getName().startsWith(String.valueOf(jobId)+"_")) {
                    glueSrcFileItem.delete();
                }
            }
        }
    }

}
 
Example #4
Source File: XxlJobExecutor.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {

        // init logpath
        XxlJobFileAppender.initLogPath(logPath);

        // init admin-client
        initAdminBizList(adminAddresses, accessToken);


        // init JobLogFileCleanThread
        JobLogFileCleanThread.getInstance().start(logRetentionDays);

        // init TriggerCallbackThread
        TriggerCallbackThread.getInstance().start();

        // init executor-server
        port = port > 0 ? port : NetUtil.findAvailablePort(9999);
        ip = (ip != null && ip.trim().length() > 0) ? ip : IpUtil.getIp();
        initRpcProvider(ip, port, appName, accessToken, registryLazy);
    }
 
Example #5
Source File: XxlJobExecutor.java    From microservices-platform with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {

        // init logpath
        XxlJobFileAppender.initLogPath(logPath);

        // init admin-client
        initAdminBizList(adminAddresses, accessToken);


        // init JobLogFileCleanThread
        JobLogFileCleanThread.getInstance().start(logRetentionDays);

        // init TriggerCallbackThread
        TriggerCallbackThread.getInstance().start();

        // init executor-server
        port = port>0?port: NetUtil.findAvailablePort(9777);
        ip = (ip!=null&&ip.trim().length()>0)?ip: IpUtil.getIp();
        initRpcProvider(ip, port, appName, accessToken);
    }
 
Example #6
Source File: ScriptJobHandler.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
public ScriptJobHandler(int jobId, long glueUpdatetime, String gluesource, GlueTypeEnum glueType) {
    this.jobId = jobId;
    this.glueUpdatetime = glueUpdatetime;
    this.gluesource = gluesource;
    this.glueType = glueType;

    // clean old script file
    File glueSrcPath = new File(XxlJobFileAppender.getGlueSrcPath());
    if (glueSrcPath.exists()) {
        File[] glueSrcFileList = glueSrcPath.listFiles();
        if (glueSrcFileList != null && glueSrcFileList.length > 0) {
            for (File glueSrcFileItem : glueSrcFileList) {
                if (glueSrcFileItem.getName().startsWith(String.valueOf(jobId) + "_")) {
                    glueSrcFileItem.delete();
                }
            }
        }
    }

}
 
Example #7
Source File: ScriptJobHandler.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
public ScriptJobHandler(int jobId, long glueUpdatetime, String gluesource, GlueTypeEnum glueType) {
    this.jobId = jobId;
    this.glueUpdatetime = glueUpdatetime;
    this.gluesource = gluesource;
    this.glueType = glueType;

    // clean old script file
    File glueSrcPath = new File(XxlJobFileAppender.getGlueSrcPath());
    if (glueSrcPath.exists()) {
        File[] glueSrcFileList = glueSrcPath.listFiles();
        if (glueSrcFileList != null && glueSrcFileList.length > 0) {
            for (File glueSrcFileItem : glueSrcFileList) {
                if (glueSrcFileItem.getName().startsWith(String.valueOf(jobId) + "_")) {
                    glueSrcFileItem.delete();
                }
            }
        }
    }

}
 
Example #8
Source File: XxlJobExecutor.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {

        // init logpath
        XxlJobFileAppender.initLogPath(logPath);

        // init admin-client
        initAdminBizList(adminAddresses, accessToken);


        // init JobLogFileCleanThread
        JobLogFileCleanThread.getInstance().start(logRetentionDays);

        // init TriggerCallbackThread
        TriggerCallbackThread.getInstance().start();

        // init executor-server
        port = port > 0 ? port : NetUtil.findAvailablePort(9999);
        ip = (ip != null && ip.trim().length() > 0) ? ip : IpUtil.getIp();
        initRpcProvider(ip, port, appName, accessToken, registryLazy);
    }
 
Example #9
Source File: ExecutorBizImpl.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<LogResult> log(long logDateTim, int logId, int fromLineNum) {
    // log filename: logPath/yyyy-MM-dd/9999.log
    String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logDateTim), logId);

    LogResult logResult = XxlJobFileAppender.readLog(logFileName, fromLineNum);
    return new ReturnT<LogResult>(logResult);
}
 
Example #10
Source File: TriggerCallbackThread.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
/**
 * callback log
 */
private void callbackLog(List<HandleCallbackParam> callbackParamList, String logContent){
    for (HandleCallbackParam callbackParam: callbackParamList) {
        String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId());
        XxlJobContext.setXxlJobContext(new XxlJobContext(
                -1,
                logFileName,
                -1,
                -1));
        XxlJobLogger.log(logContent);
    }
}
 
Example #11
Source File: ExecutorBizImpl.java    From xxl-job with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReturnT<LogResult> log(LogParam logParam) {
    // log filename: logPath/yyyy-MM-dd/9999.log
    String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logParam.getLogDateTim()), logParam.getLogId());

    LogResult logResult = XxlJobFileAppender.readLog(logFileName, logParam.getFromLineNum());
    return new ReturnT<LogResult>(logResult);
}
 
Example #12
Source File: TriggerCallbackThread.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * callback log
 */
private void callbackLog(List<HandleCallbackParam> callbackParamList, String logContent) {
    for (HandleCallbackParam callbackParam : callbackParamList) {
        String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId());
        XxlJobFileAppender.contextHolder.set(logFileName);
        XxlJobLogger.log(logContent);
    }
}
 
Example #13
Source File: ExecutorBizImpl.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<LogResult> log(long logDateTim, int logId, int fromLineNum) {
    // log filename: logPath/yyyy-MM-dd/9999.log
    String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logDateTim), logId);

    LogResult logResult = XxlJobFileAppender.readLog(logFileName, fromLineNum);
    return new ReturnT<LogResult>(logResult);
}
 
Example #14
Source File: TriggerCallbackThread.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
/**
 * callback log
 */
private void callbackLog(List<HandleCallbackParam> callbackParamList, String logContent) {
    for (HandleCallbackParam callbackParam : callbackParamList) {
        String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId());
        XxlJobFileAppender.contextHolder.set(logFileName);
        XxlJobLogger.log(logContent);
    }
}
 
Example #15
Source File: ExecutorBizImpl.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<LogResult> log(long logDateTim, int logId, int fromLineNum) {
    // log filename: logPath/yyyy-MM-dd/9999.log
    String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logDateTim), logId);

    LogResult logResult = XxlJobFileAppender.readLog(logFileName, fromLineNum);
    return new ReturnT<LogResult>(logResult);
}
 
Example #16
Source File: TriggerCallbackThread.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
/**
 * callback log
 */
private void callbackLog(List<HandleCallbackParam> callbackParamList, String logContent){
    for (HandleCallbackParam callbackParam: callbackParamList) {
        String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId());
        XxlJobFileAppender.contextHolder.set(logFileName);
        XxlJobLogger.log(logContent);
    }
}
 
Example #17
Source File: ExecutorBizImpl.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<LogResult> log(long logDateTim, int logId, int fromLineNum) {
    // log filename: logPath/yyyy-MM-dd/9999.log
    String logFileName = XxlJobFileAppender.makeLogFileName(new Date(logDateTim), logId);

    LogResult logResult = XxlJobFileAppender.readLog(logFileName, fromLineNum);
    return new ReturnT<LogResult>(logResult);
}
 
Example #18
Source File: ScriptJobHandler.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

    if (!glueType.isScript()) {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "glueType["+ glueType +"] invalid.");
    }

    // cmd
    String cmd = glueType.getCmd();

    // make script file
    String scriptFileName = XxlJobFileAppender.getGlueSrcPath()
            .concat("/")
            .concat(String.valueOf(jobId))
            .concat("_")
            .concat(String.valueOf(glueUpdatetime))
            .concat(glueType.getSuffix());
    ScriptUtil.markScriptFile(scriptFileName, gluesource);

    // log file
    String logFileName = XxlJobFileAppender.contextHolder.get();

    // script params:0=param、1=分片序号、2=分片总数
    ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
    String[] scriptParams = new String[3];
    scriptParams[0] = param;
    scriptParams[1] = String.valueOf(shardingVO.getIndex());
    scriptParams[2] = String.valueOf(shardingVO.getTotal());

    // invoke
    XxlJobLogger.log("----------- script file:"+ scriptFileName +" -----------");
    int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, scriptParams);
    ReturnT<String> result = (exitValue==0)?IJobHandler.SUCCESS:new ReturnT<String>(IJobHandler.FAIL.getCode(), "script exit value("+exitValue+") is failed");
    return result;
}
 
Example #19
Source File: JobLogFileCleanThread.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
public void start(final long logRetentionDays) {

        // limit min value
        if (logRetentionDays < 3) {
            return;
        }

        localThread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (!toStop) {
                    try {
                        // clean log dir, over logRetentionDays
                        File[] childDirs = new File(XxlJobFileAppender.getLogPath()).listFiles();
                        if (childDirs != null && childDirs.length > 0) {

                            // today
                            Calendar todayCal = Calendar.getInstance();
                            todayCal.set(Calendar.HOUR_OF_DAY, 0);
                            todayCal.set(Calendar.MINUTE, 0);
                            todayCal.set(Calendar.SECOND, 0);
                            todayCal.set(Calendar.MILLISECOND, 0);

                            Date todayDate = todayCal.getTime();

                            for (File childFile : childDirs) {

                                // valid
                                if (!childFile.isDirectory()) {
                                    continue;
                                }
                                if (childFile.getName().indexOf("-") == -1) {
                                    continue;
                                }

                                // file create date
                                Date logFileCreateDate = null;
                                try {
                                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                                    logFileCreateDate = simpleDateFormat.parse(childFile.getName());
                                } catch (ParseException e) {
                                    logger.error(e.getMessage(), e);
                                }
                                if (logFileCreateDate == null) {
                                    continue;
                                }

                                if ((todayDate.getTime() - logFileCreateDate.getTime()) >= logRetentionDays * (24 * 60 * 60 * 1000)) {
                                    FileUtil.deleteRecursively(childFile);
                                }

                            }
                        }

                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }

                    try {
                        TimeUnit.DAYS.sleep(1);
                    } catch (InterruptedException e) {
                        logger.error(e.getMessage(), e);
                    }
                }
                logger.info(">>>>>>>>>>> xxl-job, executor JobLogFileCleanThread thread destory.");

            }
        });
        localThread.setDaemon(true);
        localThread.start();
    }
 
Example #20
Source File: ScriptJobHandler.java    From zuihou-admin-boot with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {

    if (!glueType.isScript()) {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "glueType[" + glueType + "] invalid.");
    }

    // cmd
    String cmd = glueType.getCmd();

    // make script file
    String scriptFileName = XxlJobFileAppender.getGlueSrcPath()
            .concat(File.separator)
            .concat(String.valueOf(jobId))
            .concat("_")
            .concat(String.valueOf(glueUpdatetime))
            .concat(glueType.getSuffix());
    File scriptFile = new File(scriptFileName);
    if (!scriptFile.exists()) {
        ScriptUtil.markScriptFile(scriptFileName, gluesource);
    }

    // log file
    String logFileName = XxlJobFileAppender.contextHolder.get();

    // script params:0=param、1=分片序号、2=分片总数
    ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
    String[] scriptParams = new String[3];
    scriptParams[0] = param;
    scriptParams[1] = String.valueOf(shardingVO.getIndex());
    scriptParams[2] = String.valueOf(shardingVO.getTotal());

    // invoke
    XxlJobLogger.log("----------- script file:" + scriptFileName + " -----------");
    int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, scriptParams);

    if (exitValue == 0) {
        return IJobHandler.SUCCESS;
    } else {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "script exit value(" + exitValue + ") is failed");
    }

}
 
Example #21
Source File: ScriptJobHandler.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> execute2(String param) throws Exception {

    if (!glueType.isScript()) {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "glueType[" + glueType + "] invalid.");
    }

    // cmd
    String cmd = glueType.getCmd();

    // make script file
    String scriptFileName = XxlJobFileAppender.getGlueSrcPath()
            .concat(File.separator)
            .concat(String.valueOf(jobId))
            .concat("_")
            .concat(String.valueOf(glueUpdatetime))
            .concat(glueType.getSuffix());
    File scriptFile = new File(scriptFileName);
    if (!scriptFile.exists()) {
        ScriptUtil.markScriptFile(scriptFileName, gluesource);
    }

    // log file
    String logFileName = XxlJobFileAppender.contextHolder.get();

    // script params:0=param、1=分片序号、2=分片总数
    ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
    String[] scriptParams = new String[3];
    scriptParams[0] = param;
    scriptParams[1] = String.valueOf(shardingVO.getIndex());
    scriptParams[2] = String.valueOf(shardingVO.getTotal());

    // invoke
    XxlJobLogger.log("----------- script file:" + scriptFileName + " -----------");
    int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, scriptParams);

    if (exitValue == 0) {
        return IJobHandler.SUCCESS;
    } else {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "script exit value(" + exitValue + ") is failed");
    }

}
 
Example #22
Source File: JobLogFileCleanThread.java    From zuihou-admin-cloud with Apache License 2.0 4 votes vote down vote up
public void start(final long logRetentionDays) {

        // limit min value
        if (logRetentionDays < 3) {
            return;
        }

        localThread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (!toStop) {
                    try {
                        // clean log dir, over logRetentionDays
                        File[] childDirs = new File(XxlJobFileAppender.getLogPath()).listFiles();
                        if (childDirs != null && childDirs.length > 0) {

                            // today
                            Calendar todayCal = Calendar.getInstance();
                            todayCal.set(Calendar.HOUR_OF_DAY, 0);
                            todayCal.set(Calendar.MINUTE, 0);
                            todayCal.set(Calendar.SECOND, 0);
                            todayCal.set(Calendar.MILLISECOND, 0);

                            Date todayDate = todayCal.getTime();

                            for (File childFile : childDirs) {

                                // valid
                                if (!childFile.isDirectory()) {
                                    continue;
                                }
                                if (childFile.getName().indexOf("-") == -1) {
                                    continue;
                                }

                                // file create date
                                Date logFileCreateDate = null;
                                try {
                                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                                    logFileCreateDate = simpleDateFormat.parse(childFile.getName());
                                } catch (ParseException e) {
                                    logger.error(e.getMessage(), e);
                                }
                                if (logFileCreateDate == null) {
                                    continue;
                                }

                                if ((todayDate.getTime() - logFileCreateDate.getTime()) >= logRetentionDays * (24 * 60 * 60 * 1000)) {
                                    FileUtil.deleteRecursively(childFile);
                                }

                            }
                        }

                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }

                    try {
                        TimeUnit.DAYS.sleep(1);
                    } catch (InterruptedException e) {
                        logger.error(e.getMessage(), e);
                    }
                }
                logger.info(">>>>>>>>>>> xxl-job, executor JobLogFileCleanThread thread destory.");

            }
        });
        localThread.setDaemon(true);
        localThread.start();
    }
 
Example #23
Source File: JobLogFileCleanThread.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
public void start(final long logRetentionDays){

        // limit min value
        if (logRetentionDays < 3 ) {
            return;
        }

        localThread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (!toStop) {
                    try {
                        // clean log dir, over logRetentionDays
                        File[] childDirs = new File(XxlJobFileAppender.getLogPath()).listFiles();
                        if (childDirs!=null && childDirs.length>0) {

                            // today
                            Calendar todayCal = Calendar.getInstance();
                            todayCal.set(Calendar.HOUR_OF_DAY,0);
                            todayCal.set(Calendar.MINUTE,0);
                            todayCal.set(Calendar.SECOND,0);
                            todayCal.set(Calendar.MILLISECOND,0);

                            Date todayDate = todayCal.getTime();

                            for (File childFile: childDirs) {

                                // valid
                                if (!childFile.isDirectory()) {
                                    continue;
                                }
                                if (childFile.getName().indexOf("-") == -1) {
                                    continue;
                                }

                                // file create date
                                Date logFileCreateDate = null;
                                try {
                                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                                    logFileCreateDate = simpleDateFormat.parse(childFile.getName());
                                } catch (ParseException e) {
                                    logger.error(e.getMessage(), e);
                                }
                                if (logFileCreateDate == null) {
                                    continue;
                                }

                                if ((todayDate.getTime()-logFileCreateDate.getTime()) >= logRetentionDays * (24 * 60 * 60 * 1000) ) {
                                    FileUtil.deleteRecursively(childFile);
                                }

                            }
                        }

                    } catch (Exception e) {
                        if (!toStop) {
                            logger.error(e.getMessage(), e);
                        }

                    }

                    try {
                        TimeUnit.DAYS.sleep(1);
                    } catch (InterruptedException e) {
                        if (!toStop) {
                            logger.error(e.getMessage(), e);
                        }
                    }
                }
                logger.info(">>>>>>>>>>> xxl-job, executor JobLogFileCleanThread thread destory.");

            }
        });
        localThread.setDaemon(true);
        localThread.start();
    }
 
Example #24
Source File: ScriptJobHandler.java    From microservices-platform with Apache License 2.0 4 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

    if (!glueType.isScript()) {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "glueType["+ glueType +"] invalid.");
    }

    // cmd
    String cmd = glueType.getCmd();

    // make script file
    String scriptFileName = XxlJobFileAppender.getGlueSrcPath()
            .concat(File.separator)
            .concat(String.valueOf(jobId))
            .concat("_")
            .concat(String.valueOf(glueUpdatetime))
            .concat(glueType.getSuffix());
    File scriptFile = new File(scriptFileName);
    if (!scriptFile.exists()) {
        ScriptUtil.markScriptFile(scriptFileName, gluesource);
    }

    // log file
    String logFileName = XxlJobFileAppender.contextHolder.get();

    // script params:0=param、1=分片序号、2=分片总数
    ShardingUtil.ShardingVO shardingVO = ShardingUtil.getShardingVo();
    String[] scriptParams = new String[3];
    scriptParams[0] = param;
    scriptParams[1] = String.valueOf(shardingVO.getIndex());
    scriptParams[2] = String.valueOf(shardingVO.getTotal());

    // invoke
    XxlJobLogger.log("----------- script file:"+ scriptFileName +" -----------");
    int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, scriptParams);

    if (exitValue == 0) {
        return IJobHandler.SUCCESS;
    } else {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "script exit value("+exitValue+") is failed");
    }

}
 
Example #25
Source File: ScriptJobHandler.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ReturnT<String> execute(String param) throws Exception {

    if (!glueType.isScript()) {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "glueType["+ glueType +"] invalid.");
    }

    // cmd
    String cmd = glueType.getCmd();

    // make script file
    String scriptFileName = XxlJobFileAppender.getGlueSrcPath()
            .concat(File.separator)
            .concat(String.valueOf(jobId))
            .concat("_")
            .concat(String.valueOf(glueUpdatetime))
            .concat(glueType.getSuffix());
    File scriptFile = new File(scriptFileName);
    if (!scriptFile.exists()) {
        ScriptUtil.markScriptFile(scriptFileName, gluesource);
    }

    // log file
    String logFileName = XxlJobContext.getXxlJobContext().getJobLogFileName();

    // script params:0=param、1=分片序号、2=分片总数
    String[] scriptParams = new String[3];
    scriptParams[0] = param;
    scriptParams[1] = String.valueOf(XxlJobContext.getXxlJobContext().getShardIndex());
    scriptParams[2] = String.valueOf(XxlJobContext.getXxlJobContext().getShardTotal());

    // invoke
    XxlJobLogger.log("----------- script file:"+ scriptFileName +" -----------");
    int exitValue = ScriptUtil.execToFile(cmd, scriptFileName, logFileName, scriptParams);

    if (exitValue == 0) {
        return IJobHandler.SUCCESS;
    } else {
        return new ReturnT<String>(IJobHandler.FAIL.getCode(), "script exit value("+exitValue+") is failed");
    }

}
 
Example #26
Source File: JobLogFileCleanThread.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
public void start(final long logRetentionDays){

        // limit min value
        if (logRetentionDays < 3 ) {
            return;
        }

        localThread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (!toStop) {
                    try {
                        // clean log dir, over logRetentionDays
                        File[] childDirs = new File(XxlJobFileAppender.getLogPath()).listFiles();
                        if (childDirs!=null && childDirs.length>0) {

                            // today
                            Calendar todayCal = Calendar.getInstance();
                            todayCal.set(Calendar.HOUR_OF_DAY,0);
                            todayCal.set(Calendar.MINUTE,0);
                            todayCal.set(Calendar.SECOND,0);
                            todayCal.set(Calendar.MILLISECOND,0);

                            Date todayDate = todayCal.getTime();

                            for (File childFile: childDirs) {

                                // valid
                                if (!childFile.isDirectory()) {
                                    continue;
                                }
                                if (childFile.getName().indexOf("-") == -1) {
                                    continue;
                                }

                                // file create date
                                Date logFileCreateDate = null;
                                try {
                                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                                    logFileCreateDate = simpleDateFormat.parse(childFile.getName());
                                } catch (ParseException e) {
                                    logger.error(e.getMessage(), e);
                                }
                                if (logFileCreateDate == null) {
                                    continue;
                                }

                                if ((todayDate.getTime()-logFileCreateDate.getTime()) >= logRetentionDays * (24 * 60 * 60 * 1000) ) {
                                    FileUtil.deleteRecursively(childFile);
                                }

                            }
                        }

                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }

                    try {
                        TimeUnit.DAYS.sleep(1);
                    } catch (InterruptedException e) {
                        logger.error(e.getMessage(), e);
                    }
                }
                logger.info(">>>>>>>>>>> xxl-job, executor JobLogFileCleanThread thread destory.");

            }
        });
        localThread.setDaemon(true);
        localThread.start();
    }
 
Example #27
Source File: JobLogFileCleanThread.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
public void start(final long logRetentionDays){

        // limit min value
        if (logRetentionDays < 3 ) {
            return;
        }

        localThread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (!toStop) {
                    try {
                        // clean log dir, over logRetentionDays
                        File[] childDirs = new File(XxlJobFileAppender.getLogPath()).listFiles();
                        if (childDirs!=null && childDirs.length>0) {

                            // today
                            Calendar todayCal = Calendar.getInstance();
                            todayCal.set(Calendar.HOUR_OF_DAY,0);
                            todayCal.set(Calendar.MINUTE,0);
                            todayCal.set(Calendar.SECOND,0);
                            todayCal.set(Calendar.MILLISECOND,0);

                            Date todayDate = todayCal.getTime();

                            for (File childFile: childDirs) {

                                // valid
                                if (!childFile.isDirectory()) {
                                    continue;
                                }
                                if (childFile.getName().indexOf("-") == -1) {
                                    continue;
                                }

                                // file create date
                                Date logFileCreateDate = null;
                                try {
                                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                                    logFileCreateDate = simpleDateFormat.parse(childFile.getName());
                                } catch (ParseException e) {
                                    logger.error(e.getMessage(), e);
                                }
                                if (logFileCreateDate == null) {
                                    continue;
                                }

                                if ((todayDate.getTime()-logFileCreateDate.getTime()) >= logRetentionDays * (24 * 60 * 60 * 1000) ) {
                                    FileUtil.deleteRecursively(childFile);
                                }

                            }
                        }

                    } catch (Exception e) {
                        if (!toStop) {
                            logger.error(e.getMessage(), e);
                        }

                    }

                    try {
                        TimeUnit.DAYS.sleep(1);
                    } catch (InterruptedException e) {
                        if (!toStop) {
                            logger.error(e.getMessage(), e);
                        }
                    }
                }
                logger.info(">>>>>>>>>>> xxl-job, executor JobLogFileCleanThread thread destory.");

            }
        });
        localThread.setDaemon(true);
        localThread.setName("xxl-job, executor JobLogFileCleanThread");
        localThread.start();
    }
 
Example #28
Source File: XxlJobExecutor.java    From xxl-job with GNU General Public License v3.0 4 votes vote down vote up
public void start() throws Exception {

        // init logpath
        XxlJobFileAppender.initLogPath(logPath);

        // init invoker, admin-client
        initAdminBizList(adminAddresses, accessToken);


        // init JobLogFileCleanThread
        JobLogFileCleanThread.getInstance().start(logRetentionDays);

        // init TriggerCallbackThread
        TriggerCallbackThread.getInstance().start();

        // init executor-server
        initEmbedServer(address, ip, port, appname, accessToken);
    }