mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-07-01 21:07:25 +00:00
[Change] ImageCacheStore 优化中断处理, 自动取消任务, 补充TaskState设置;
This commit is contained in:
@ -66,17 +66,17 @@ public final class ImageCacheStore {
|
|||||||
// 置任务状态
|
// 置任务状态
|
||||||
task.taskState.set(TaskState.RUNNING);
|
task.taskState.set(TaskState.RUNNING);
|
||||||
|
|
||||||
Throwable throwable = null;
|
Future<Throwable> future = imageCacheExecutor.submit(() -> {
|
||||||
|
try {
|
||||||
|
handler.getImageToCache(cacheObject);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
Throwable throwable;
|
||||||
try {
|
try {
|
||||||
throwable = imageCacheExecutor.submit(() -> {
|
throwable = future.get();
|
||||||
try {
|
|
||||||
handler.getImageToCache(cacheObject);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}).get();
|
|
||||||
|
|
||||||
if(throwable == null) {
|
if(throwable == null) {
|
||||||
task.taskState.set(TaskState.COMPLETE);
|
task.taskState.set(TaskState.COMPLETE);
|
||||||
} else {
|
} else {
|
||||||
@ -84,6 +84,12 @@ public final class ImageCacheStore {
|
|||||||
}
|
}
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
log.error("执行图片缓存任务时发生异常", e);
|
log.error("执行图片缓存任务时发生异常", e);
|
||||||
|
task.taskState.set(TaskState.ERROR);
|
||||||
|
return e.getCause();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
future.cancel(true);
|
||||||
|
task.taskState.set(TaskState.ERROR);
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
return throwable;
|
return throwable;
|
||||||
} finally {
|
} finally {
|
||||||
|
Reference in New Issue
Block a user