Skip to content

Commit d04751b

Browse files
committed
deal with quartz job : remark
1 parent 5d486cf commit d04751b

4 files changed

Lines changed: 54 additions & 4 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace Blog.Core.Common.Helper
7+
{
8+
public class StringHelper
9+
{
10+
/// <summary>
11+
/// 根据分隔符返回前n条数据
12+
/// </summary>
13+
/// <param name="content">数据内容</param>
14+
/// <param name="separator">分隔符</param>
15+
/// <param name="top">前n条</param>
16+
/// <param name="isDesc">是否倒序(默认false)</param>
17+
/// <returns></returns>
18+
public static List<string> GetTopDataBySeparator(string content, string separator, int top, bool isDesc = false)
19+
{
20+
if (string.IsNullOrEmpty(content))
21+
{
22+
return new List<string>() { };
23+
}
24+
25+
if (string.IsNullOrEmpty(separator))
26+
{
27+
throw new ArgumentException("message", nameof(separator));
28+
}
29+
30+
var dataArray = content.Split(separator).Where(d => !string.IsNullOrEmpty(d)).ToArray();
31+
if (isDesc)
32+
{
33+
Array.Reverse(dataArray);
34+
}
35+
36+
if (top > 0)
37+
{
38+
dataArray = dataArray.Take(top).ToArray();
39+
}
40+
41+
return dataArray.ToList();
42+
}
43+
}
44+
}

Blog.Core.Tasks/QuartzNet/Jobs/Job_Blogs_Quartz.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Blog.Core.IServices;
1+
using Blog.Core.Common.Helper;
2+
using Blog.Core.IServices;
23
using Quartz;
34
using System;
45
using System.Threading.Tasks;
@@ -51,7 +52,12 @@ public async Task Run(IJobExecutionContext context, int jobid)
5152
if (model != null)
5253
{
5354
model.RunTimes += 1;
54-
model.Remark += $"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】【执行成功】<br>";
55+
var separator = "<br>";
56+
model.Remark =
57+
$"【{DateTime.Now}】执行任务【Id:{context.JobDetail.Key.Name},组别:{context.JobDetail.Key.Group}】【执行成功】{separator}"
58+
+ string.Join(separator, StringHelper.GetTopDataBySeparator(model.Remark, separator, 9, true))
59+
+ separator;
60+
5561
await _tasksQzServices.Update(model);
5662
}
5763
}

Blog.Core/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public class Program
1010
{
1111
public static void Main(string[] args)
1212
{
13+
//初始化默认主机Builder
1314
Host.CreateDefaultBuilder(args)
1415
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
1516
.ConfigureWebHostDefaults(webBuilder =>
1617
{
1718
webBuilder
1819
.UseStartup<Startup>()
19-
.UseUrls("http://localhost:8081")
2020
.ConfigureLogging((hostingContext, builder) =>
2121
{
2222
//过滤掉系统默认的一些日志

Blog.Core/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"Name": "Blog.Core"
1616
}
1717
},
18-
//"urls": "http://localhost:8081",
18+
"urls": "http://localhost:8081",
1919
"AllowedHosts": "*",
2020
"AppSettings": {
2121
"RedisCachingAOP": {

0 commit comments

Comments
 (0)