优化任务通知格式并记录完成时间
This commit is contained in:
parent
72f8ab597a
commit
ccc05fda19
@ -58,17 +58,19 @@ public class GalleryManageService {
|
||||
User user = userMapper.selectUserByAuthCode(AuthCode);
|
||||
// return Response._failure("调试中,请勿提交任务");
|
||||
|
||||
if (remoteService.isDead()) {
|
||||
response.failure("节点挂了,找狮子处理");
|
||||
pushService.taskCreateReport(user.getUsername(), link, response);
|
||||
return response.toJSONString();
|
||||
}
|
||||
int gid;
|
||||
try {
|
||||
gid = Integer.parseInt(link.split("/")[4]);
|
||||
} catch (NumberFormatException e) {
|
||||
response.failure("链接错误");
|
||||
pushService.taskCreateReport(user.getUsername(), link, response);
|
||||
pushService.taskCreateReport(user.getUsername(), "未知任务", response);
|
||||
return response.toJSONString();
|
||||
}
|
||||
String taskName = "任务 [" + gid + "]";
|
||||
|
||||
if (remoteService.isDead()) {
|
||||
response.failure("节点挂了,找狮子处理");
|
||||
pushService.taskCreateReport(user.getUsername(), taskName, response);
|
||||
return response.toJSONString();
|
||||
}
|
||||
Gallery gallery;
|
||||
@ -76,7 +78,7 @@ public class GalleryManageService {
|
||||
//判断数据库中是否有这个任务,有则返回状态
|
||||
if ((gallery = galleryMapper.selectGalleryByGid(gid)) != null) {
|
||||
response.failure("任务队列已有此任务,任务状态: " + gallery.getStatus() + " 请点击查找任务");
|
||||
pushService.taskCreateReport(user.getUsername(), link, response);
|
||||
pushService.taskCreateReport(user.getUsername(), gallery.getName(), response);
|
||||
return response.toJSONString();
|
||||
}
|
||||
|
||||
@ -86,25 +88,26 @@ public class GalleryManageService {
|
||||
if (gallery == null || !gallery.getStatus().equals("已提交")) {
|
||||
log.error("创建任务失败: {},", link);
|
||||
response.failure("提交任务失败,未知原因,请检查链接是否正常");
|
||||
pushService.taskCreateReport(user.getUsername(), link, response);
|
||||
pushService.taskCreateReport(user.getUsername(), taskName, response);
|
||||
return response.toJSONString();
|
||||
} else {
|
||||
taskName = gallery.getName();
|
||||
log.info("创建任务: {} 目标分辨率:{}", link, targetResolution);
|
||||
if (remoteService.addGalleryToQueue(gallery) != 0) {
|
||||
log.error("传送任务{}失败, 未知原因", gallery.getName());
|
||||
response.failure("任务传送失败,未知原因,尝试点击重连按钮看看");
|
||||
pushService.taskCreateReport(user.getUsername(), link, response);
|
||||
pushService.taskCreateReport(user.getUsername(), taskName, response);
|
||||
return response.toJSONString();
|
||||
}
|
||||
}
|
||||
} catch (ResolutionNotMatchException e) {
|
||||
response.failure("提交失败,分辨率不存在");
|
||||
pushService.taskCreateReport(user.getUsername(), link, response);
|
||||
pushService.taskCreateReport(user.getUsername(), taskName, response);
|
||||
return response.toJSONString();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
response.failure("IO错误,可能是网络波动");
|
||||
pushService.taskCreateReport(user.getUsername(), link, response);
|
||||
pushService.taskCreateReport(user.getUsername(), taskName, response);
|
||||
return response.toJSONString();
|
||||
}
|
||||
|
||||
@ -122,7 +125,7 @@ public class GalleryManageService {
|
||||
response.failure("提交失败,未知原因");
|
||||
galleryMapper.deleteGalleryByGid(gallery.getGid());
|
||||
}
|
||||
pushService.taskCreateReport(user.getUsername(), link, response);
|
||||
pushService.taskCreateReport(user.getUsername(), taskName, response);
|
||||
|
||||
return response.toJSONString();
|
||||
}
|
||||
|
||||
@ -8,6 +8,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
@ -15,17 +19,21 @@ public class PushService {
|
||||
|
||||
long self = 686839482;
|
||||
|
||||
private static final DateTimeFormatter COMPLETION_TIME_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.of("Asia/Shanghai"));
|
||||
|
||||
final TelegramBot bot;
|
||||
|
||||
public void taskCreateReport(String username, String link, Response response){
|
||||
public void taskCreateReport(String username, String taskName, Response response){
|
||||
if(response.isSuccess())
|
||||
sendToMe(String.format("用户%s提交下载%s", username, link));
|
||||
sendToMe(String.format("用户%s提交下载任务:%s", username, taskName));
|
||||
else
|
||||
sendToMe(String.format("用户%s提交下载%s , 下载失败:%s", username, link, response.get("data")));
|
||||
sendToMe(String.format("用户%s提交下载任务:%s,下载失败:%s", username, taskName, response.get("data")));
|
||||
}
|
||||
|
||||
public void downloadComplete(Gallery gallery){
|
||||
sendToMe(gallery.getLink() + " 下载完成");
|
||||
String completionTime = COMPLETION_TIME_FORMATTER.format(Instant.now());
|
||||
sendToMe(String.format("任务下载完成:%s\n完成时间:%s", gallery.getName(), completionTime));
|
||||
}
|
||||
|
||||
public void storageNodeOnline(){
|
||||
|
||||
@ -263,7 +263,9 @@ public class RemoteService {
|
||||
gallery.setName(galleryTask.getName());
|
||||
|
||||
if(galleryTask.getStatus() == GalleryTask.COMPRESS_COMPLETE) {
|
||||
boolean justCompleted = !"下载完成".equals(gallery.getStatus());
|
||||
gallery.setStatus("下载完成");
|
||||
if (justCompleted)
|
||||
pushService.downloadComplete(gallery);
|
||||
}
|
||||
else if(galleryTask.getStatus() == GalleryTask.COMPRESSING)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user