|
|
@ -1,14 +1,18 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Concurrent; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Data.SqlClient; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Linq.Dynamic.Core; |
|
|
|
using System.Net; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Cronos; |
|
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using SettleAccount.Job.SignalR; |
|
|
@ -163,7 +167,7 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
catch(CronFormatException ex) |
|
|
|
catch (CronFormatException ex) |
|
|
|
{ |
|
|
|
Console.WriteLine($"{job.Name},Cron解析失败:{ex.Message},{ex.ToString()}"); |
|
|
|
} |
|
|
@ -191,8 +195,10 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
|
|
|
|
private void JobItemFaild(Guid id, Guid jobLogId, Exception ex) |
|
|
|
{ |
|
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
|
using var connection = new SqlConnection(connectionString); |
|
|
|
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connection).Options; |
|
|
|
using var db = new SettleAccountDbContext(options); |
|
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
|
if (entity != null) |
|
|
|
{ |
|
|
@ -207,8 +213,10 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
|
|
|
|
private void JobItemSuccess(Guid id, Guid jobLogId) |
|
|
|
{ |
|
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
|
using var connection = new SqlConnection(connectionString); |
|
|
|
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connection).Options; |
|
|
|
using var db = new SettleAccountDbContext(options); |
|
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
|
if (entity != null) |
|
|
|
{ |
|
|
@ -225,8 +233,10 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
|
|
|
|
private void JobItemStop(Guid id) |
|
|
|
{ |
|
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
|
using var connection = new SqlConnection(connectionString); |
|
|
|
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connection).Options; |
|
|
|
using var db = new SettleAccountDbContext(options); |
|
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
|
if (entity != null) |
|
|
|
{ |
|
|
@ -240,8 +250,10 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
|
|
|
|
private Guid? JobItemStart(Guid id) |
|
|
|
{ |
|
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
|
using var connection = new SqlConnection(connectionString); |
|
|
|
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connection).Options; |
|
|
|
using var db = new SettleAccountDbContext(options); |
|
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
|
if (entity != null) |
|
|
|
{ |
|
|
@ -256,14 +268,20 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
|
|
|
|
private JobItem GetJobItem(Guid id) |
|
|
|
{ |
|
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
|
return scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>().Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
|
using var connection = new SqlConnection(connectionString); |
|
|
|
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connection).Options; |
|
|
|
using var db = new SettleAccountDbContext(options); |
|
|
|
var repo = db.Set<JobItem>(); |
|
|
|
return repo.FirstOrDefault(o => o.Id == id); |
|
|
|
} |
|
|
|
|
|
|
|
private void JobItemHeartBeat(Guid id) |
|
|
|
{ |
|
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
|
using var connection = new SqlConnection(connectionString); |
|
|
|
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connection).Options; |
|
|
|
using var db = new SettleAccountDbContext(options); |
|
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
|
if (entity != null) |
|
|
|
{ |
|
|
@ -299,8 +317,10 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
protected override Task ExecuteAsync(CancellationToken stoppingToken) |
|
|
|
{ |
|
|
|
this._stoppingToken = stoppingToken; |
|
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
|
using var connection = new SqlConnection(connectionString); |
|
|
|
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connection).Options; |
|
|
|
using var db = new SettleAccountDbContext(options); |
|
|
|
var jobs = db.Set<JobItem>().ToList(); |
|
|
|
jobs.ForEach(this.AddJob); |
|
|
|
return Task.CompletedTask; |
|
|
|