删除作业已不存在的任务

This commit is contained in:
大石头 2024-09-19 14:34:12 +08:00
parent 39fa220bba
commit ae24ba9964
5 changed files with 15 additions and 5 deletions

View File

@ -4,6 +4,7 @@ using NewLife;
using NewLife.Data;
using NewLife.Threading;
using XCode;
using XCode.DataAccessLayer;
namespace AntJob.Data.Entity;

View File

@ -150,14 +150,14 @@ public partial class JobTask : EntityBase<JobTask>
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);
}
@ -207,6 +207,10 @@ public partial class JobTask : EntityBase<JobTask>
//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()

View File

@ -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
{

View File

@ -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="作业错误。计算作业在执行过程中所发生的错误">

View File

@ -145,6 +145,9 @@ public class Worker : IHostedService
p += list.Count;
}
// 删除作业已不存在的任务
rs += JobTask.DeleteNoJob();
if (rs > 0)
{
sw.Stop();