修复多线程同时修改任务导致状态有问题的bug;减小预览图像素;修改任务状态发送条件;
This commit is contained in:
parent
fb5ff43364
commit
b0f27784dc
@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="MavenProjectsManager">
|
||||
|
||||
@ -15,6 +15,8 @@ public class GalleryTask {
|
||||
|
||||
public static byte COMPRESS_COMPLETE = 4;
|
||||
|
||||
public static byte COMPRESSING = 5;
|
||||
|
||||
|
||||
public static byte DOWNLOAD_ALL = 3;
|
||||
public static byte DOWNLOAD_PREVIEW = 2;
|
||||
@ -47,4 +49,9 @@ public class GalleryTask {
|
||||
public boolean is_compress_complete(){
|
||||
return status == COMPRESS_COMPLETE;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean is_compressing(){
|
||||
return status == COMPRESSING;
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,6 +55,12 @@ public class DownloadCheckService {
|
||||
//扫描进度
|
||||
Iterator<File> fileIterator = files.iterator();
|
||||
for(GalleryTask galleryTask: queue){
|
||||
//跳过已经下载完成或者压缩完成的任务
|
||||
if(galleryTask.is_download_complete()
|
||||
|| galleryTask.is_compress_complete()
|
||||
|| galleryTask.is_compressing())
|
||||
continue;
|
||||
|
||||
while(fileIterator.hasNext()){
|
||||
File file = fileIterator.next();
|
||||
if(!file.getName().contains(String.valueOf(galleryTask.getGid())))
|
||||
@ -78,8 +84,10 @@ public class DownloadCheckService {
|
||||
|
||||
//转格式队列
|
||||
for(GalleryTask galleryTask: queue)
|
||||
if (galleryTask.is_download_complete())
|
||||
if (galleryTask.is_download_complete()) {
|
||||
galleryTask.setStatus(GalleryTask.COMPRESSING);
|
||||
convert_queue.add(galleryTask);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -102,7 +110,7 @@ public class DownloadCheckService {
|
||||
galleryTask.setStatus(ErrorCode.COMPRESS_ERROR);
|
||||
continue;
|
||||
}
|
||||
//长度相同比较字典序,否则比较长度
|
||||
//仅比较字典序
|
||||
images = Arrays.stream(images).sorted(Comparator.naturalOrder()).toArray(File[]::new);
|
||||
|
||||
//创建文件夹
|
||||
@ -135,6 +143,7 @@ public class DownloadCheckService {
|
||||
operation = new IMOperation();
|
||||
operation.addImage(images[i].getAbsolutePath());
|
||||
operation.format("webp");
|
||||
operation.resize(2000, 2000);
|
||||
operation.addImage(storagePath + galleryTask.getName() + "/" + images[i].getName().replace(".png", ".webp").replace(".jpg", ".webp"));
|
||||
try {
|
||||
convertCmd.run(operation);
|
||||
@ -144,12 +153,13 @@ public class DownloadCheckService {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((galleryTask.getType() & GalleryTask.DOWNLOAD_SOURCE) != 0) {
|
||||
ZipUtil.zip(galleryTask.getPath(), storagePath + galleryTask.getName() + "/" + galleryTask.getName() + ".zip");
|
||||
log.info(galleryTask.getName() + "压缩完成" );
|
||||
}
|
||||
FileUtil.del(galleryTask.getPath());
|
||||
galleryTask.setStatus(GalleryTask.DOWNLOAD_COMPLETE);
|
||||
galleryTask.setStatus(GalleryTask.COMPRESS_COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,7 +20,6 @@ import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.ListIterator;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@ -84,7 +83,7 @@ public class storageNode {
|
||||
}
|
||||
lock.unlock();
|
||||
//检查
|
||||
if (!downloadCheckService.downloadCheck()) {
|
||||
if (!downloadCheckService.downloadCheck() && queue.isEmpty()) {
|
||||
counter++;
|
||||
if(server != null && server.isActive() && counter > 10) {
|
||||
server.writeAndFlush(new MaintainMessage());
|
||||
@ -93,19 +92,15 @@ public class storageNode {
|
||||
return;
|
||||
}
|
||||
//发送
|
||||
//上锁后再发送,避免出现发送完之后再下载完成
|
||||
lock.lock();
|
||||
DownloadStatusMessage downloadStatusMessage = new DownloadStatusMessage();
|
||||
downloadStatusMessage.setGalleryTasks(queue.toArray(GalleryTask[]::new));
|
||||
server.writeAndFlush(downloadStatusMessage);
|
||||
|
||||
ListIterator<GalleryTask> listIterator = queue.listIterator();
|
||||
lock.lock();
|
||||
while (listIterator.hasNext()) {
|
||||
GalleryTask galleryTask = listIterator.next();
|
||||
if (galleryTask.is_download_complete())
|
||||
listIterator.remove();
|
||||
}
|
||||
lock.unlock();
|
||||
log.info("任务状态发送完成");
|
||||
|
||||
queue.removeIf(GalleryTask::is_compress_complete);
|
||||
lock.unlock();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
try (OutputStream outputStream = new FileOutputStream("/root/gallery/storageNode/err.txt")){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user