11111111
private class Task implements Runnable {
@Override
public void run() {
while (!Thread.currentThread().isInterrupted()) {
try {
PictureCompressDTO picture = compressQueue.pollTask();
if (picture != null) {
log.info("获取到压缩任务, 当前队列长度 {}", compressQueue.getSize());
CompletableFuture<SyncCompressTaskDTO> resultFuture = picture.getResultFuture();
String tmpPath = picture.getTmpPath();
byte[] bytes = FileUtil.readBytes(tmpPath);
// 上传到 minio
//String location = minioBaseService.upload(BUCKET_BAMBOO, picture.getFileName(), bytes, picture.getContentType());
String location = minioBaseService.upload(BUCKET_BAMBOO, picture.getFileName(), tmpPath, picture.getContentType());
byte[] compressedImage = ImageUtil.compressForScale(bytes, picture.getDesFileSize());
SyncCompressTaskDTO dto = new SyncCompressTaskDTO();
dto.setCompressedData(compressedImage);
dto.setOriginalFileMinioLocation(location);
// 处理完成后将结果传回
resultFuture.complete(dto);
}
} catch (InterruptedException e) {
// 处理中断信号
Thread.currentThread().interrupt();
log.error("Task interrupted", e);
} catch (Exception e) {
log.error("Error during picture compression", e);
}
}
}
}