Skip to content

Commit

Permalink
CronJob增加字段控制是否打印日志
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Oct 17, 2023
1 parent 4e4a6bc commit 6c0b9d8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
11 changes: 11 additions & 0 deletions NewLife.Cube/Entity/Cube.htm
Original file line number Diff line number Diff line change
Expand Up @@ -3157,6 +3157,17 @@ <h3>定时作业(CronJob)</h3>
<td></td>
</tr>

<tr>
<td>EnableLog</td>
<td>启用日志</td>
<td>Boolean</td>
<td></td>
<td></td>
<td></td>
<td>N</td>
<td></td>
</tr>

<tr>
<td>LastTime</td>
<td>最后时间</td>
Expand Down
9 changes: 4 additions & 5 deletions NewLife.Cube/Entity/Cube.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<EntityModel xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="https://newlifex.com https://newlifex.com/Model202309.xsd" xmlns="https://newlifex.com/Model202309.xsd">
<EntityModel xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="https://newlifex.com https://newlifex.com/Model202309.xsd" Document="https://newlifex.com/xcode/model" xmlns="https://newlifex.com/Model202309.xsd">
<Option>
<!--类名模板。其中{name}替换为Table.Name,如{name}Model/I{name}Dto等-->
<ClassNameTemplate />
Expand All @@ -17,6 +17,8 @@
<ModelNameForCopy />
<!--带有索引器。实现IModel接口-->
<HasIModel>False</HasIModel>
<!--可为null上下文。生成String?等-->
<Nullable>False</Nullable>
<!--数据库连接名-->
<ConnName>Cube</ConnName>
<!--模型类模版。设置后生成模型类,用于接口数据传输,例如{name}Model-->
Expand All @@ -31,10 +33,6 @@
<ModelNameForToModel />
<!--命名格式。Default/Upper/Lower/Underline-->
<NameFormat>Default</NameFormat>
<!--生成器版本-->
<Version>11.9.2023.0910</Version>
<!--帮助文档-->
<Document>https://newlifex.com/xcode/model</Document>
<!--魔方区域显示名-->
<DisplayName />
<!--魔方控制器输出目录-->
Expand Down Expand Up @@ -399,6 +397,7 @@
<Column Name="Method" DataType="String" Length="200" Description="命令。作业方法全名,含命名空间和类名,静态方法,包含一个String参数" />
<Column Name="Argument" DataType="String" Length="2000" Description="参数。方法参数,时间日期、网址、SQL等" />
<Column Name="Enable" DataType="Boolean" Description="启用" />
<Column Name="EnableLog" DataType="Boolean" Description="启用日志" />
<Column Name="LastTime" DataType="DateTime" Description="最后时间。最后一次执行作业的时间" />
<Column Name="NextTime" DataType="DateTime" Description="下一次时间。下一次执行作业的时间" />
<Column Name="CreateUserID" DataType="Int32" Description="创建者" Category="扩展" />
Expand Down
Binary file modified NewLife.Cube/Entity/xcodetool.exe
Binary file not shown.
1 change: 1 addition & 0 deletions NewLife.Cube/Entity/定时作业.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public static CronJob Add(String name, MethodInfo method, String cron, Boolean e
Method = $"{method.DeclaringType.FullName}.{method.Name}",
Cron = cron,
Enable = enable,
EnableLog = true,
Remark = method.GetDescription(),
};

Expand Down
16 changes: 16 additions & 0 deletions NewLife.Cube/Entity/定时作业.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public partial class CronJob
[BindColumn("Enable", "启用", "")]
public Boolean Enable { get => _Enable; set { if (OnPropertyChanging("Enable", value)) { _Enable = value; OnPropertyChanged("Enable"); } } }

private Boolean _EnableLog;
/// <summary>启用日志</summary>
[DisplayName("启用日志")]
[Description("启用日志")]
[DataObjectField(false, false, false, 0)]
[BindColumn("EnableLog", "启用日志", "")]
public Boolean EnableLog { get => _EnableLog; set { if (OnPropertyChanging("EnableLog", value)) { _EnableLog = value; OnPropertyChanged("EnableLog"); } } }

private DateTime _LastTime;
/// <summary>最后时间。最后一次执行作业的时间</summary>
[DisplayName("最后时间")]
Expand Down Expand Up @@ -173,6 +181,7 @@ public override Object this[String name]
"Method" => _Method,
"Argument" => _Argument,
"Enable" => _Enable,
"EnableLog" => _EnableLog,
"LastTime" => _LastTime,
"NextTime" => _NextTime,
"CreateUserID" => _CreateUserID,
Expand All @@ -195,6 +204,7 @@ public override Object this[String name]
case "Method": _Method = Convert.ToString(value); break;
case "Argument": _Argument = Convert.ToString(value); break;
case "Enable": _Enable = value.ToBoolean(); break;
case "EnableLog": _EnableLog = value.ToBoolean(); break;
case "LastTime": _LastTime = value.ToDateTime(); break;
case "NextTime": _NextTime = value.ToDateTime(); break;
case "CreateUserID": _CreateUserID = value.ToInt(); break;
Expand Down Expand Up @@ -238,6 +248,9 @@ public partial class _
/// <summary>启用</summary>
public static readonly Field Enable = FindByName("Enable");

/// <summary>启用日志</summary>
public static readonly Field EnableLog = FindByName("EnableLog");

/// <summary>最后时间。最后一次执行作业的时间</summary>
public static readonly Field LastTime = FindByName("LastTime");

Expand Down Expand Up @@ -292,6 +305,9 @@ public partial class __
/// <summary>启用</summary>
public const String Enable = "Enable";

/// <summary>启用日志</summary>
public const String EnableLog = "EnableLog";

/// <summary>最后时间。最后一次执行作业的时间</summary>
public const String LastTime = "LastTime";

Expand Down
2 changes: 2 additions & 0 deletions NewLife.CubeNC/Services/JobService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ private void DoJob(Object state)
#region 辅助
internal static void WriteLog(String action, Boolean success, String remark, CronJob job)
{
if (!job.EnableLog) return;

var log = LogProvider.Provider.CreateLog("JobService", action, success, remark);
if (job != null) log.LinkID = job.Id;
log.TraceId = DefaultSpan.Current?.TraceId;
Expand Down

0 comments on commit 6c0b9d8

Please sign in to comment.