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);
}
}
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));
}
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 + "的处理结果");
}
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;
}
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);
}
Aggregations