Search in sources :

Example 11 with SaturnJobReturn

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

the class SaturnScriptJob method innerHandleWithListener.

protected SaturnJobReturn innerHandleWithListener(String jobName, Integer item, String execParameter, SaturnExecutionContext shardingContext) {
    ShardingItemCallable callable = createShardingItemCallable(jobName, item, execParameter, shardingContext);
    shardingItemCallableList.add(callable);
    beforeExecution(callable);
    SaturnJobReturn saturnJobReturn = null;
    try {
        saturnJobReturn = innerHandle(callable);
    } catch (Throwable t) {
        LogUtils.error(log, jobName, t.getMessage(), t);
        saturnJobReturn = new SaturnJobReturn(SaturnSystemReturnCode.USER_FAIL, t.getMessage(), SaturnSystemErrorGroup.FAIL);
    }
    callable.setSaturnJobReturn(saturnJobReturn);
    afterExecution(callable);
    LogUtils.debug(log, jobName, "job:{} item:{} finish execution, which takes {}ms", jobName, item, callable.getExecutionTime());
    return saturnJobReturn;
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) ShardingItemCallable(com.vip.saturn.job.basic.ShardingItemCallable)

Example 12 with SaturnJobReturn

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

the class ExecutionService method registerJobCompletedReportInfoByItem.

/**
 * 作业完成信息注册,此信息用于页面展现。注意,无论作业是否上报状态(对应/config/enabledReport/节点),都会注册此信息。
 */
public void registerJobCompletedReportInfoByItem(final JobExecutionMultipleShardingContext jobExecutionShardingContext, int item, Date nextFireTimePausePeriodEffected) {
    ExecutionInfo info = reportService.getInfoByItem(item);
    if (info == null) {
        // old data has been flushed to zk.
        info = new ExecutionInfo(item);
    }
    if (jobExecutionShardingContext instanceof SaturnExecutionContext) {
        // 为了展现分片处理失败的状态
        SaturnExecutionContext saturnContext = (SaturnExecutionContext) jobExecutionShardingContext;
        if (saturnContext.isSaturnJob()) {
            SaturnJobReturn jobRet = saturnContext.getShardingItemResults().get(item);
            if (jobRet != null) {
                int errorGroup = jobRet.getErrorGroup();
                info.setJobMsg(jobRet.getReturnMsg());
                // 如果作业执行成功且不展示日志,则不展现log
                if (errorGroup == SaturnSystemErrorGroup.SUCCESS && !configService.showNormalLog()) {
                    info.setJobLog(null);
                } else {
                    info.setJobLog(saturnContext.getJobLog(item));
                }
            } else {
                info.setJobMsg(NO_RETURN_VALUE);
            }
        }
    }
    if (nextFireTimePausePeriodEffected != null) {
        info.setNextFireTime(nextFireTimePausePeriodEffected.getTime());
    }
    info.setLastCompleteTime(System.currentTimeMillis());
    reportService.fillInfoOnAfter(info);
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) ExecutionInfo(com.vip.saturn.job.internal.control.ExecutionInfo)

Example 13 with SaturnJobReturn

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

the class ExecutionService method updateErrorJobReturnIfPossible.

private void updateErrorJobReturnIfPossible(JobExecutionMultipleShardingContext jobExecutionShardingContext, int item) {
    if (jobExecutionShardingContext instanceof SaturnExecutionContext) {
        // 为了展现分片处理失败的状态
        SaturnExecutionContext saturnContext = (SaturnExecutionContext) jobExecutionShardingContext;
        if (!saturnContext.isSaturnJob()) {
            return;
        }
        SaturnJobReturn jobRet = saturnContext.getShardingItemResults().get(item);
        try {
            if (jobRet != null) {
                int errorGroup = jobRet.getErrorGroup();
                if (errorGroup == SaturnSystemErrorGroup.TIMEOUT) {
                    getJobNodeStorage().createJobNodeIfNeeded(ExecutionNode.getTimeoutNode(item));
                } else if (errorGroup != SaturnSystemErrorGroup.SUCCESS) {
                    getJobNodeStorage().createJobNodeIfNeeded(ExecutionNode.getFailedNode(item));
                }
            } else {
                getJobNodeStorage().createJobNodeIfNeeded(ExecutionNode.getFailedNode(item));
            }
        } catch (RegException e) {
            LogUtils.warn(log, jobName, "update job return fail.", e);
        }
    }
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) RegException(com.vip.saturn.job.reg.exception.RegException)

Example 14 with SaturnJobReturn

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

the class ReturnParamJavaJob method handleJavaJob.

@Override
public SaturnJobReturn handleJavaJob(String jobName, Integer shardItem, String shardParam, SaturnJobExecutionContext shardingContext) {
    String key = jobName + "_" + shardItem;
    Integer status = statusMap.get(key);
    int count = 0;
    if (status != null) {
        count = status;
    }
    count++;
    statusMap.put(key, count);
    System.out.println(new Date() + " running:" + jobName + "; " + shardItem + ";" + shardParam + "; count:" + count);
    return new SaturnJobReturn(shardParam);
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) Date(java.util.Date)

Example 15 with SaturnJobReturn

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

the class SimpleJavaJob method handleJavaJob.

@Override
public SaturnJobReturn handleJavaJob(String jobName, Integer shardItem, String shardParam, SaturnJobExecutionContext shardingContext) {
    String key = jobName + "_" + shardItem;
    System.out.println(new Date() + " running:" + jobName + "; " + shardItem + ";" + shardParam);
    countInc(key);
    return new SaturnJobReturn(" result:" + jobName + "; " + shardItem + ";" + shardParam);
}
Also used : SaturnJobReturn(com.vip.saturn.job.SaturnJobReturn) Date(java.util.Date)

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