Skip to content

Commit

Permalink
删除作业已不存在的任务
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Sep 19, 2024
1 parent 39fa220 commit ae24ba9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions AntJob.Data/Entity/作业.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NewLife.Data;
using NewLife.Threading;
using XCode;
using XCode.DataAccessLayer;

namespace AntJob.Data.Entity;

Expand Down
10 changes: 7 additions & 3 deletions AntJob.Data/Entity/作业任务.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ public static IEnumerable<JobTask> Search(Int32 id, Int32 appid, Int32 jobid, Jo
var exp = new WhereExpression();

if (id > 0) exp &= _.ID == id;
if (appid > 0) exp &= _.AppID == appid;
if (jobid > 0) exp &= _.JobID == jobid;
if (appid >= 0) exp &= _.AppID == appid;
if (jobid >= 0) exp &= _.JobID == jobid;
if (status >= JobStatus.就绪) exp &= _.Status == status;
if (!client.IsNullOrEmpty()) exp &= _.Client == client;
if (!key.IsNullOrEmpty()) exp &= _.Data.Contains(key) | _.Message.Contains(key) | _.Key == key;

exp &= _.DataTime.Between(dataStart, dataEnd);
exp &= _.DataTime.Between(start, end);
exp &= _.UpdateTime.Between(start, end);

return FindAll(exp, p);
}
Expand Down Expand Up @@ -207,6 +207,10 @@ public void Reset()

//public static Int32 DeleteByAppId(Int32 appid) => Delete(_.AppID == appid);

/// <summary>删除作业已不存在的任务</summary>
/// <returns></returns>
public static Int32 DeleteNoJob() => Delete(_.JobID.NotIn(Entity.Job.FindSQLWithKey()));

/// <summary>转模型类</summary>
/// <returns></returns>
public TaskModel ToModel()
Expand Down
3 changes: 2 additions & 1 deletion AntJob.Data/Entity/作业任务.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ namespace AntJob.Data.Entity;
[DataObject]
[Description("作业任务。计算作业在执行过程中生成的任务实例,具有该次执行所需参数")]
[BindIndex("IX_JobTask_JobID_DataTime", false, "JobID,DataTime")]
[BindIndex("IX_JobTask_AppID_Client_Status", false, "AppID,Client,Status")]
[BindIndex("IX_JobTask_JobID_CreateTime", false, "JobID,CreateTime")]
[BindIndex("IX_JobTask_JobID_UpdateTime", false, "JobID,UpdateTime")]
[BindIndex("IX_JobTask_AppID_Client_Status", false, "AppID,Client,Status")]
[BindTable("JobTask", Description = "作业任务。计算作业在执行过程中生成的任务实例,具有该次执行所需参数", ConnName = "Ant", DbType = DatabaseType.None)]
public partial class JobTask
{
Expand Down
3 changes: 2 additions & 1 deletion AntJob.Data/Model.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@
</Columns>
<Indexes>
<Index Columns="JobID,DataTime" />
<Index Columns="AppID,Client,Status" />
<Index Columns="JobID,CreateTime" />
<Index Columns="JobID,UpdateTime" />
<Index Columns="AppID,Client,Status" />
</Indexes>
</Table>
<Table Name="JobError" Description="作业错误。计算作业在执行过程中所发生的错误">
Expand Down
3 changes: 3 additions & 0 deletions AntJob.Server/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ private static void ClearItems(Object state)
p += list.Count;
}

// 删除作业已不存在的任务
rs += JobTask.DeleteNoJob();

if (rs > 0)
{
sw.Stop();
Expand Down

0 comments on commit ae24ba9

Please sign in to comment.