Search in sources :

Example 1 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class AbstractSaturnJob method updateExecuteResult.

protected void updateExecuteResult(SaturnJobReturn saturnJobReturn, SaturnExecutionContext saturnContext, int item) {
    int successCount = 0;
    int errorCount = 0;
    SaturnJobReturn jobReturn = saturnJobReturn;
    if (jobReturn == null) {
        jobReturn = new SaturnJobReturn(SaturnSystemReturnCode.SYSTEM_FAIL, "Can not find the corresponding SaturnJobReturn", SaturnSystemErrorGroup.FAIL);
        errorCount++;
    } else {
        if (SaturnSystemReturnCode.JOB_NO_COUNT != jobReturn.getReturnCode()) {
            int errorGroup = jobReturn.getErrorGroup();
            if (errorGroup == SaturnSystemErrorGroup.SUCCESS) {
                successCount++;
            } else {
                if (errorGroup == SaturnSystemErrorGroup.TIMEOUT) {
                    onTimeout(item);
                } else if (errorGroup == SaturnSystemErrorGroup.FAIL_NEED_RAISE_ALARM) {
                    onNeedRaiseAlarm(item, jobReturn.getReturnMsg());
                }
                errorCount++;
            }
        }
    }
    // 为了展现分片处理失败的状态
    saturnContext.getShardingItemResults().put(item, jobReturn);
    // 执行次数加1
    ProcessCountStatistics.increaseTotalCountDelta(executorName, jobName);
    // 只要有出错和失败的分片,就认为是处理失败; 否则认为处理成功
    if (errorCount == 0 && successCount >= 0) {
        ProcessCountStatistics.incrementProcessSuccessCount(executorName, jobName, successCount);
    } else {
        ProcessCountStatistics.increaseErrorCountDelta(executorName, jobName);
        ProcessCountStatistics.incrementProcessFailureCount(executorName, jobName, errorCount);
    }
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn)

Example 2 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class ExecutionService method registerJobCompletedControlInfoByItem.

/**
 * 注册作业完成信息.
 */
public void registerJobCompletedControlInfoByItem(final JobExecutionMultipleShardingContext jobExecutionShardingContext, int item) {
    boolean isEnabledReport = configService.isEnabledReport();
    if (!isEnabledReport) {
        return;
    }
    if (jobExecutionShardingContext instanceof SaturnExecutionContext) {
        // 为了展现分片处理失败的状态
        SaturnExecutionContext saturnContext = (SaturnExecutionContext) jobExecutionShardingContext;
        if (saturnContext.isSaturnJob()) {
            SaturnJobReturn jobRet = saturnContext.getShardingItemResults().get(item);
            if (jobRet != null) {
                int errorGroup = jobRet.getErrorGroup();
                if (errorGroup == SaturnSystemErrorGroup.TIMEOUT) {
                    getJobNodeStorage().createJobNodeIfNeeded(ExecutionNode.getTimeoutNode(item));
                } else if (errorGroup == SaturnSystemErrorGroup.FAIL) {
                    getJobNodeStorage().createJobNodeIfNeeded(ExecutionNode.getFailedNode(item));
                }
            } else {
                getJobNodeStorage().createJobNodeIfNeeded(ExecutionNode.getFailedNode(item));
            }
        }
    }
    // create completed node
    getJobNodeStorage().createOrUpdateJobNodeWithValue(ExecutionNode.getCompletedNode(item), executorName);
    // remove running node
    getJobNodeStorage().removeJobNodeIfExisted(ExecutionNode.getRunningNode(item));
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) SaturnExecutionContext(com.vip.saturn.job.basic.SaturnExecutionContext)

Example 3 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class DemoJob method handleJavaJob.

@Override
public SaturnJobReturn handleJavaJob(String jobName, Integer shardItem, String shardParam, SaturnJobExecutionContext shardingContext) throws InterruptedException {
    DemoService demoService = (DemoService) SpringFactory.getInstance().getObject("demoService");
    demoService.execute();
    System.out.println("我会出现在运行日志里.running handleJavaJob:" + jobName + "; " + shardItem + ";" + shardParam);
    return new SaturnJobReturn("我是分片" + shardItem + "的处理结果");
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) DemoService(com.vip.saturn.demo.service.DemoService)

Example 4 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class ScriptJobRunner method handleException.

private SaturnJobReturn handleException(long timeoutSeconds, Exception e) {
    SaturnJobReturn saturnJobReturn;
    String errMsg = e.toString();
    if (watchdog.isTimeout()) {
        saturnJobReturn = new SaturnJobReturn(SaturnSystemReturnCode.SYSTEM_FAIL, String.format("execute job timeout(%sms), %s", timeoutSeconds * 1000, errMsg), SaturnSystemErrorGroup.TIMEOUT);
        LogUtils.error(log, jobName, "{}-{} timeout, {}", jobName, item, errMsg);
        return saturnJobReturn;
    }
    if (watchdog.isForceStop()) {
        saturnJobReturn = new SaturnJobReturn(SaturnSystemReturnCode.SYSTEM_FAIL, "the job was forced to stop, " + errMsg, SaturnSystemErrorGroup.FAIL);
        LogUtils.error(log, jobName, "{}-{} force stopped, {}", jobName, item, errMsg);
        return saturnJobReturn;
    }
    saturnJobReturn = new SaturnJobReturn(SaturnSystemReturnCode.USER_FAIL, "Exception: " + errMsg, SaturnSystemErrorGroup.FAIL);
    LogUtils.error(log, jobName, "{}-{} Exception: {}", jobName, item, errMsg, e);
    return saturnJobReturn;
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn)

Example 5 with SaturnJobReturn

use of com.vip.saturn.job.SaturnJobReturn in project Saturn by vipshop.

the class JsonParseObjectTest method readSaturnJobReturn.

private SaturnJobReturn readSaturnJobReturn(String filepath) throws Exception {
    Map<String, String> envMap = new HashMap<>();
    envMap.put(SystemEnvProperties.NAME_VIP_SATURN_OUTPUT_PATH, this.getClass().getResource(filepath).getFile());
    ScriptJobRunner scriptJobRunner = new ScriptJobRunner(envMap, null, null, null, null);
    Method createSaturnJobReturnFileMethod = scriptJobRunner.getClass().getDeclaredMethod("createSaturnJobReturnFile");
    createSaturnJobReturnFileMethod.setAccessible(true);
    createSaturnJobReturnFileMethod.invoke(scriptJobRunner);
    Method readSaturnJobReturnMethod = scriptJobRunner.getClass().getDeclaredMethod("readSaturnJobReturn");
    readSaturnJobReturnMethod.setAccessible(true);
    return (SaturnJobReturn) readSaturnJobReturnMethod.invoke(scriptJobRunner);
}
Also used : ScriptJobRunner(com.vip.saturn.job.shell.ScriptJobRunner) SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) HashMap(java.util.HashMap) Method(java.lang.reflect.Method)

Aggregations

SaturnJobReturn (com.vip.saturn.job.SaturnJobReturn)35 LogbackListAppender (com.vip.saturn.job.executor.utils.LogbackListAppender)9 HashMap (java.util.HashMap)9 Test (org.junit.Test)9 Date (java.util.Date)4 JobInitAlarmException (com.vip.saturn.job.exception.JobInitAlarmException)2 UncaughtExceptionHandler (java.lang.Thread.UncaughtExceptionHandler)2 ExecutorService (java.util.concurrent.ExecutorService)2 DemoService (com.vip.saturn.demo.service.DemoService)1 SaturnExecutionContext (com.vip.saturn.job.basic.SaturnExecutionContext)1 ShardingItemCallable (com.vip.saturn.job.basic.ShardingItemCallable)1 ExecutionInfo (com.vip.saturn.job.internal.control.ExecutionInfo)1 RegException (com.vip.saturn.job.reg.exception.RegException)1 ScriptJobRunner (com.vip.saturn.job.shell.ScriptJobRunner)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CommandLine (org.apache.commons.exec.CommandLine)1