Skip to content

Commit a0df09e

Browse files
committed
Merge pull request #13 from qq254963746/develop
客户端提交,过载 处理改为 保存重发
2 parents 0a91431 + 9ef8cdb commit a0df09e

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

job-client/src/main/java/com/lts/job/client/RetryJobClient.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import com.lts.job.client.domain.JobClientNode;
55
import com.lts.job.client.domain.Response;
66
import com.lts.job.client.domain.ResponseCode;
7+
import com.lts.job.client.support.JobSubmitProtectException;
78
import com.lts.job.core.domain.Job;
8-
import com.lts.job.core.exception.JobSubmitException;
99
import com.lts.job.core.support.RetryScheduler;
1010

1111
import java.util.Arrays;
@@ -49,22 +49,30 @@ protected void innerStop() {
4949
}
5050

5151
@Override
52-
public Response submitJob(Job job) throws JobSubmitException {
52+
public Response submitJob(Job job) {
5353
return submitJob(Arrays.asList(job));
5454
}
5555

5656
@Override
57-
public Response submitJob(List<Job> jobs) throws JobSubmitException {
58-
Response response = superSubmitJob(jobs);
59-
57+
public Response submitJob(List<Job> jobs) {
58+
Response response;
59+
try {
60+
response = superSubmitJob(jobs);
61+
} catch (JobSubmitProtectException e) {
62+
response = new Response();
63+
response.setSuccess(true);
64+
response.setFailedJobs(jobs);
65+
response.setCode(ResponseCode.SUBMIT_TOO_BUSY_AND_SAVE_FOR_LATER);
66+
response.setMsg(response.getMsg() + ", submit too busy , save local fail store and send later !");
67+
}
6068
if (!response.isSuccess()) {
6169
try {
6270
for (Job job : response.getFailedJobs()) {
6371
retryScheduler.inSchedule(job.getTaskId(), job);
6472
}
6573
response.setSuccess(true);
66-
response.setCode(ResponseCode.FAILED_AND_SAVE_FILE);
67-
response.setMsg(response.getMsg() + ", but save local fail store and send later !");
74+
response.setCode(ResponseCode.SUBMIT_FAILED_AND_SAVE_FOR_LATER);
75+
response.setMsg(response.getMsg() + ", save local fail store and send later !");
6876
} catch (Exception e) {
6977
response.setSuccess(false);
7078
response.setMsg(e.getMessage());
@@ -74,7 +82,7 @@ public Response submitJob(List<Job> jobs) throws JobSubmitException {
7482
return response;
7583
}
7684

77-
private Response superSubmitJob(List<Job> jobs) throws JobSubmitException {
85+
private Response superSubmitJob(List<Job> jobs) {
7886
return super.submitJob(jobs);
7987
}
8088
}

job-client/src/main/java/com/lts/job/client/domain/ResponseCode.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ private ResponseCode(){}
1212
public static final String JOB_TRACKER_NOT_FOUND = "11";
1313

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

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

20+
// 提交太块
21+
public static final String SUBMIT_TOO_BUSY_AND_SAVE_FOR_LATER = "14";
22+
2023
}

job-core/src/main/java/com/lts/job/core/exception/JobSubmitException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* @author Robert HG (254963746@qq.com) on 5/12/15.
55
*/
6-
public class JobSubmitException extends Exception {
6+
public class JobSubmitException extends RuntimeException {
77

88
public JobSubmitException() {
99
super();

0 commit comments

Comments
 (0)