|
|
@@ -5,13 +5,28 @@
|
|
|
/// </summary>
|
|
|
public class JobClusterServer : IJobClusterServer
|
|
|
{
|
|
|
+ private readonly SqlSugarRepository<SysJobCluster> _sysJobClusterRep;
|
|
|
+
|
|
|
+ public JobClusterServer(SqlSugarRepository<SysJobCluster> sysJobClusterRep)
|
|
|
+ {
|
|
|
+ _sysJobClusterRep = sysJobClusterRep;
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 当前作业调度器启动通知
|
|
|
/// </summary>
|
|
|
/// <param name="context">作业集群服务上下文</param>
|
|
|
- public void Start(JobClusterContext context)
|
|
|
+ public async void Start(JobClusterContext context)
|
|
|
{
|
|
|
// 在作业集群表中,如果 clusterId 不存在,则新增一条(否则更新一条),并设置 status 为 ClusterStatus.Waiting
|
|
|
+ if (await _sysJobClusterRep.IsAnyAsync(u => u.ClusterId == context.ClusterId))
|
|
|
+ {
|
|
|
+ await _sysJobClusterRep.UpdateSetColumnsTrueAsync(u => new SysJobCluster { Status = ClusterStatus.Waiting }, u => u.ClusterId == context.ClusterId);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ await _sysJobClusterRep.InsertAsync(new SysJobCluster { ClusterId = context.ClusterId, Status = ClusterStatus.Waiting });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -31,8 +46,10 @@ public class JobClusterServer : IJobClusterServer
|
|
|
// 1) 如果作业集群表已有 status 为 ClusterStatus.Working 则继续循环
|
|
|
// 2) 如果作业集群表中还没有其他服务或只有自己,则插入一条集群服务或调用 await WorkNowAsync(clusterId); 之后 return;
|
|
|
// 3) 如果作业集群表中没有 status 为 ClusterStatus.Working 的,调用 await WorkNowAsync(clusterId); 之后 return;
|
|
|
+ if (await _sysJobClusterRep.IsAnyAsync(u => u.Status == ClusterStatus.Working))
|
|
|
+ continue;
|
|
|
|
|
|
- await WorkNowAsync(clusterId);
|
|
|
+ WorkNowAsync(clusterId);
|
|
|
return;
|
|
|
}
|
|
|
catch { }
|
|
|
@@ -46,18 +63,20 @@ public class JobClusterServer : IJobClusterServer
|
|
|
/// 当前作业调度器停止通知
|
|
|
/// </summary>
|
|
|
/// <param name="context">作业集群服务上下文</param>
|
|
|
- public void Stop(JobClusterContext context)
|
|
|
+ public async void Stop(JobClusterContext context)
|
|
|
{
|
|
|
// 在作业集群表中,更新 clusterId 的 status 为 ClusterStatus.Crashed
|
|
|
+ await _sysJobClusterRep.UpdateSetColumnsTrueAsync(u => new SysJobCluster { Status = ClusterStatus.Crashed }, u => u.ClusterId == context.ClusterId);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 当前作业调度器宕机
|
|
|
/// </summary>
|
|
|
/// <param name="context">作业集群服务上下文</param>
|
|
|
- public void Crash(JobClusterContext context)
|
|
|
+ public async void Crash(JobClusterContext context)
|
|
|
{
|
|
|
// 在作业集群表中,更新 clusterId 的 status 为 ClusterStatus.Crashed
|
|
|
+ await _sysJobClusterRep.UpdateSetColumnsTrueAsync(u => new SysJobCluster { Status = ClusterStatus.Crashed }, u => u.ClusterId == context.ClusterId);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -65,10 +84,9 @@ public class JobClusterServer : IJobClusterServer
|
|
|
/// </summary>
|
|
|
/// <param name="clusterId">集群 Id</param>
|
|
|
/// <returns></returns>
|
|
|
- private Task WorkNowAsync(string clusterId)
|
|
|
+ private async void WorkNowAsync(string clusterId)
|
|
|
{
|
|
|
// 在作业集群表中,更新 clusterId 的 status 为 ClusterStatus.Working
|
|
|
-
|
|
|
- return Task.CompletedTask;
|
|
|
+ await _sysJobClusterRep.UpdateSetColumnsTrueAsync(u => new SysJobCluster { Status = ClusterStatus.Working }, u => u.ClusterId == clusterId);
|
|
|
}
|
|
|
}
|