Skip to content

Commit

Permalink
Merge pull request #13 from qq254963746/develop
Browse files Browse the repository at this point in the history
客户端提交,过载 处理改为 保存重发
  • Loading branch information
qq254963746 committed May 26, 2015
2 parents 0a91431 + 9ef8cdb commit a0df09e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
24 changes: 16 additions & 8 deletions job-client/src/main/java/com/lts/job/client/RetryJobClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.lts.job.client.domain.JobClientNode;
import com.lts.job.client.domain.Response;
import com.lts.job.client.domain.ResponseCode;
import com.lts.job.client.support.JobSubmitProtectException;
import com.lts.job.core.domain.Job;
import com.lts.job.core.exception.JobSubmitException;
import com.lts.job.core.support.RetryScheduler;

import java.util.Arrays;
Expand Down Expand Up @@ -49,22 +49,30 @@ protected void innerStop() {
}

@Override
public Response submitJob(Job job) throws JobSubmitException {
public Response submitJob(Job job) {
return submitJob(Arrays.asList(job));
}

@Override
public Response submitJob(List<Job> jobs) throws JobSubmitException {
Response response = superSubmitJob(jobs);

public Response submitJob(List<Job> jobs) {
Response response;
try {
response = superSubmitJob(jobs);
} catch (JobSubmitProtectException e) {
response = new Response();
response.setSuccess(true);
response.setFailedJobs(jobs);
response.setCode(ResponseCode.SUBMIT_TOO_BUSY_AND_SAVE_FOR_LATER);
response.setMsg(response.getMsg() + ", submit too busy , save local fail store and send later !");
}
if (!response.isSuccess()) {
try {
for (Job job : response.getFailedJobs()) {
retryScheduler.inSchedule(job.getTaskId(), job);
}
response.setSuccess(true);
response.setCode(ResponseCode.FAILED_AND_SAVE_FILE);
response.setMsg(response.getMsg() + ", but save local fail store and send later !");
response.setCode(ResponseCode.SUBMIT_FAILED_AND_SAVE_FOR_LATER);
response.setMsg(response.getMsg() + ", save local fail store and send later !");
} catch (Exception e) {
response.setSuccess(false);
response.setMsg(e.getMessage());
Expand All @@ -74,7 +82,7 @@ public Response submitJob(List<Job> jobs) throws JobSubmitException {
return response;
}

private Response superSubmitJob(List<Job> jobs) throws JobSubmitException {
private Response superSubmitJob(List<Job> jobs) {
return super.submitJob(jobs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ private ResponseCode(){}
public static final String JOB_TRACKER_NOT_FOUND = "11";

// 提交失败并且写入文件
public static final String FAILED_AND_SAVE_FILE = "12";
public static final String SUBMIT_FAILED_AND_SAVE_FOR_LATER = "12";

// 请求参数检查失败
public static final String REQUEST_FILED_CHECK_ERROR = "13";

// 提交太块
public static final String SUBMIT_TOO_BUSY_AND_SAVE_FOR_LATER = "14";

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @author Robert HG ([email protected]) on 5/12/15.
*/
public class JobSubmitException extends Exception {
public class JobSubmitException extends RuntimeException {

public JobSubmitException() {
super();
Expand Down

0 comments on commit a0df09e

Please sign in to comment.