Skip to content

Commit 3bfc6c6

Browse files
committed
Merge pull request #39 from qq254963746/develop
add retry scheduler name
2 parents 9f6929f + 96a5a28 commit 3bfc6c6

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

lts-core/src/main/java/com/lts/core/support/RetryScheduler.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public abstract class RetryScheduler<T> {
3535
private ScheduledFuture<?> scheduledFuture;
3636
private AtomicBoolean start = new AtomicBoolean(false);
3737
private FailStore failStore;
38+
// 名称主要是用来记录日志
39+
private String name;
3840

3941
// 批量发送的消息数
4042
private int batchSize = 5;
@@ -47,6 +49,7 @@ public RetryScheduler(Application application, String storePath) {
4749
FailStoreFactory failStoreFactory = ExtensionLoader.getExtensionLoader(FailStoreFactory.class).getAdaptiveExtension();
4850
failStore = failStoreFactory.getFailStore(application.getConfig(), storePath);
4951
}
52+
5053
public RetryScheduler(Application application, String storePath, int batchSize) {
5154
this(application, storePath);
5255
this.batchSize = batchSize;
@@ -57,15 +60,19 @@ protected RetryScheduler(Application application, int batchSize) {
5760
this.batchSize = batchSize;
5861
}
5962

63+
public void setName(String name) {
64+
this.name = name;
65+
}
66+
6067
public void start() {
6168
try {
6269
if (start.compareAndSet(false, true)) {
6370
// 这个时间后面再去优化
6471
scheduledFuture = RETRY_EXECUTOR_SERVICE.scheduleWithFixedDelay(new CheckRunner(), 10, 30, TimeUnit.SECONDS);
65-
LOGGER.error("Start retry scheduler success!");
72+
LOGGER.info("Start {} retry scheduler success!", name);
6673
}
6774
} catch (Throwable t) {
68-
LOGGER.error("Start retry scheduler failed!", t);
75+
LOGGER.error("Start {} retry scheduler failed!", name, t);
6976
}
7077
}
7178

@@ -74,10 +81,10 @@ public void stop() {
7481
if (start.compareAndSet(false, true)) {
7582
scheduledFuture.cancel(true);
7683
RETRY_EXECUTOR_SERVICE.shutdown();
77-
LOGGER.error("Stop retry scheduler success!");
84+
LOGGER.info("Stop {} retry scheduler success!", name);
7885
}
7986
} catch (Throwable t) {
80-
LOGGER.error("Stop retry scheduler failed!", t);
87+
LOGGER.error("Stop {} retry scheduler failed!", name, t);
8188
}
8289
}
8390

@@ -117,7 +124,7 @@ public void run() {
117124
values.add(kvPair.getValue());
118125
}
119126
if (retry(values)) {
120-
LOGGER.info("本地数据发送成功, {}", JSONUtils.toJSONString(values));
127+
LOGGER.info("{} local files send success, {}", name, JSONUtils.toJSONString(values));
121128
failStore.delete(keys);
122129
} else {
123130
break;
@@ -137,7 +144,7 @@ public void run() {
137144
} while (CollectionUtils.isNotEmpty(kvPairs));
138145

139146
} catch (Throwable e) {
140-
LOGGER.error(e.getMessage(), e);
147+
LOGGER.error("Run {} retry scheduler error.", name, e);
141148
}
142149
}
143150

@@ -152,7 +159,7 @@ public void inSchedule(String key, T value) {
152159
failStore.close();
153160
}
154161
} catch (FailStoreException e) {
155-
LOGGER.error(e.getMessage(), e);
162+
LOGGER.error("{} in schedule error. ", e);
156163
}
157164
}
158165

lts-jobclient/src/main/java/com/lts/jobclient/RetryJobClient.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ protected boolean retry(List<Job> jobs) {
4040
return false;
4141
}
4242
};
43+
retryScheduler.setName(RetryJobClient.class.getSimpleName());
4344
super.innerStart();
4445
retryScheduler.start();
4546
}

lts-tasktracker/src/main/java/com/lts/tasktracker/logger/BizLoggerImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ protected boolean retry(List<BizLog> list) {
5151
return sendBizLog(list);
5252
}
5353
};
54+
retryScheduler.setName(BizLogger.class.getSimpleName());
5455
this.retryScheduler.start();
5556
}
5657

lts-tasktracker/src/main/java/com/lts/tasktracker/processor/JobPushProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected boolean retry(List<JobResult> jobResults) {
5151
return retrySendJobResults(jobResults);
5252
}
5353
};
54-
54+
retryScheduler.setName("JobPush");
5555
retryScheduler.start();
5656

5757
// 线程安全的

0 commit comments

Comments
 (0)