Skip to content

Commit

Permalink
perf: 优化多进程发件失败后的处理逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
uyoufu committed Apr 7, 2022
1 parent b439cbf commit df3ba13
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Server/Server/Http/Modules/SendEmail/SendTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private void SendItems(List<SendItem> sendItemList)
});

// 开始运行
Task.WhenAll(sendThreads.ConvertAll(st => st.Run(sendItemStack))).ContinueWith((task) =>
Task.WhenAll(sendThreads.ConvertAll(st => st.Run(sendItemStack,sendItemList))).ContinueWith((task) =>
{
// 执行回调
// 发送关闭命令
Expand Down
15 changes: 12 additions & 3 deletions Server/Server/Http/Modules/SendEmail/SendThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ public SendThread(string userId, SendBox sendBox, LiteDBManager liteDb)
}


// 开始发件
public Task Run(Stack<SendItem> sendItems)
/// <summary>
/// 开始发件
/// </summary>
/// <param name="sendItems">不同进程共享的栈</param>
/// <param name="sendItemsList">原始发件数据,只有成功后才移除,当数量为 0 时,所有的进程退出</param>
/// <returns></returns>
public Task Run(Stack<SendItem> sendItems, List<SendItem> sendItemsList)
{
// 创建线程
Task task = Task.Run(async () =>
{
while (sendItems.Count > 0)
while (sendItemsList.Count > 0)
{
// 开始并行发送
//确定smtp服务器地址 实例化一个Smtp客户端
Expand All @@ -92,6 +97,10 @@ public Task Run(Stack<SendItem> sendItems)
//发送邮件
smtpclient.Send(mailMessage);

// 发送成功后,马上从原始数据中移除
var index = sendItemsList.FindIndex(item => item._id == sendItem._id);
if (index > -1) sendItemsList.RemoveAt(index);

// 发送成功后,更新数据,更新到数据库
sendItem.senderEmail = _sendBox.email;
sendItem.senderName = _sendBox.userName;
Expand Down
9 changes: 4 additions & 5 deletions UI/src/views/send/components/historyDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,9 @@ export default {
computed: {
// 是否显示重新发送功能
isShowResent() {
const needResend = this.data.filter(d => !d.isSent)
return needResend.length > 0
const result = this.data.some(d => !d.isSent)
console.log('isShowResent:', result)
return result
},
resentClass() {
Expand All @@ -220,7 +221,7 @@ export default {
watch: {
data(val) {
this.disableResend = val.some(d => !d.isSent)
this.disableResend = val.every(d => d.isSent)
}
},
Expand Down Expand Up @@ -276,7 +277,6 @@ export default {
// 关闭重发,关闭取消
this.disableResend = true
this.isResending = true
this.disableCancle = true
this.getProgressInfo()
Expand Down Expand Up @@ -308,7 +308,6 @@ export default {
this.initQuasarTable_onRequest()
// 打开按钮锁定
this.disableResend = needResend.length < 1
this.disableCancle = false
this.isResending = false
// 恢复重发初始值
Expand Down

0 comments on commit df3ba13

Please sign in to comment.