重试任务时按 GID 重新检查并回传状态
This commit is contained in:
parent
8a56e9726f
commit
ce21d8724e
@ -124,29 +124,48 @@ public class DownloadCheckService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addToQueue(GalleryTask galleryTask){
|
public GalleryTask addToQueue(GalleryTask galleryTask){
|
||||||
// A reconnect can resend a task whose name is stale (for example, the
|
// A reconnect can resend a task whose name is stale (for example, the
|
||||||
// downloader appended a resolution suffix). Resolve completed archives
|
// downloader appended a resolution suffix). Resolve completed archives
|
||||||
// by gid first, because the gid is stable while the directory name is not.
|
// by gid first, because the gid is stable while the directory name is not.
|
||||||
File storedDirectory = findStoredDirectoryByGid(galleryTask.getGid());
|
File storedDirectory = findStoredDirectoryByGid(galleryTask.getGid());
|
||||||
if(storedDirectory != null){
|
if(storedDirectory != null){
|
||||||
|
queue.remove(galleryTask.getGid());
|
||||||
galleryTask.setName(storedDirectory.getName());
|
galleryTask.setName(storedDirectory.getName());
|
||||||
galleryTask.setStatus(GalleryTask.COMPRESS_COMPLETE);
|
galleryTask.setStatus(GalleryTask.COMPRESS_COMPLETE);
|
||||||
CustomUtil.notifyMe(String.format("任务:%s在添加时已下载完成,更新任务状态", galleryTask.getName()));
|
CustomUtil.notifyMe(String.format("任务:%s在添加时已下载完成,更新任务状态", galleryTask.getName()));
|
||||||
return true;
|
return galleryTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the task is still downloading, retain the actual directory name so
|
// If the task is still downloading, retain the actual directory name so
|
||||||
// subsequent progress and compression use the same identity.
|
// subsequent progress and compression use the same identity.
|
||||||
File downloadingDirectory = findDirectoryByGid(new File(downloadPath), galleryTask.getGid());
|
File downloadingDirectory = findDirectoryByGid(new File(downloadPath), galleryTask.getGid());
|
||||||
if(downloadingDirectory != null){
|
if(downloadingDirectory != null){
|
||||||
galleryTask.setName(downloadingDirectory.getName());
|
GalleryTask queuedTask = queue.get(galleryTask.getGid());
|
||||||
queue.putIfAbsent(galleryTask.getGid(), galleryTask);
|
if(queuedTask == null){
|
||||||
return false;
|
refreshDownloadingTask(galleryTask, downloadingDirectory);
|
||||||
|
queue.put(galleryTask.getGid(), galleryTask);
|
||||||
|
return galleryTask;
|
||||||
|
}
|
||||||
|
if(!queuedTask.is_compressing() && !queuedTask.is_compress_complete())
|
||||||
|
refreshDownloadingTask(queuedTask, downloadingDirectory);
|
||||||
|
return queuedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
queue.putIfAbsent(galleryTask.getGid(), galleryTask);
|
GalleryTask queuedTask = queue.putIfAbsent(galleryTask.getGid(), galleryTask);
|
||||||
return false;
|
return queuedTask == null ? galleryTask : queuedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshDownloadingTask(GalleryTask galleryTask, File downloadingDirectory){
|
||||||
|
galleryTask.setName(downloadingDirectory.getName());
|
||||||
|
File[] pages = downloadingDirectory.listFiles((dir, name) -> !name.equals("galleryinfo.txt"));
|
||||||
|
galleryTask.setProceeding(pages == null ? 0 : pages.length);
|
||||||
|
if(new File(downloadingDirectory, "galleryinfo.txt").isFile()){
|
||||||
|
galleryTask.setStatus(GalleryTask.DOWNLOAD_COMPLETE);
|
||||||
|
galleryTask.setPath(downloadingDirectory.getPath());
|
||||||
|
}else{
|
||||||
|
galleryTask.setStatus(GalleryTask.DOWNLOADING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File findStoredDirectoryByGid(int gid){
|
private File findStoredDirectoryByGid(int gid){
|
||||||
|
|||||||
@ -157,12 +157,11 @@ public class storageNode {
|
|||||||
DownloadPostMessage dpm = (DownloadPostMessage) abstractMessage;
|
DownloadPostMessage dpm = (DownloadPostMessage) abstractMessage;
|
||||||
lock.lock();
|
lock.lock();
|
||||||
try {
|
try {
|
||||||
//添加到队列方法返回真说明该任务已下载完成,直接发送下载进度
|
//每次收到任务都重新检查并立即回传当前状态,供主站的单任务重试接口使用
|
||||||
if(downloadCheckService.addToQueue(dpm.getGalleryTask())){
|
GalleryTask currentTask = downloadCheckService.addToQueue(dpm.getGalleryTask());
|
||||||
DownloadStatusMessage downloadStatusMessage = new DownloadStatusMessage();
|
DownloadStatusMessage downloadStatusMessage = new DownloadStatusMessage();
|
||||||
downloadStatusMessage.setGalleryTasks(new GalleryTask[]{dpm.getGalleryTask()});
|
downloadStatusMessage.setGalleryTasks(new GalleryTask[]{currentTask});
|
||||||
server.writeAndFlush(downloadStatusMessage);
|
server.writeAndFlush(downloadStatusMessage);
|
||||||
}
|
|
||||||
log.info(String.valueOf(queue));
|
log.info(String.valueOf(queue));
|
||||||
} finally {
|
} finally {
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user