|
@ -1,14 +1,18 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Concurrent; |
|
|
using System.Collections.Concurrent; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.Data.SqlClient; |
|
|
using System.Diagnostics; |
|
|
using System.Diagnostics; |
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
|
|
|
using System.Linq.Dynamic.Core; |
|
|
using System.Net; |
|
|
using System.Net; |
|
|
using System.Threading; |
|
|
using System.Threading; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
using Cronos; |
|
|
using Cronos; |
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
using Microsoft.AspNetCore.SignalR; |
|
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.Hosting; |
|
|
using Microsoft.Extensions.Hosting; |
|
|
using SettleAccount.Job.SignalR; |
|
|
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()}"); |
|
|
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) |
|
|
private void JobItemFaild(Guid id, Guid jobLogId, Exception ex) |
|
|
{ |
|
|
{ |
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
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); |
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
if (entity != null) |
|
|
if (entity != null) |
|
|
{ |
|
|
{ |
|
@ -207,8 +213,10 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
|
|
|
|
|
private void JobItemSuccess(Guid id, Guid jobLogId) |
|
|
private void JobItemSuccess(Guid id, Guid jobLogId) |
|
|
{ |
|
|
{ |
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
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); |
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
if (entity != null) |
|
|
if (entity != null) |
|
|
{ |
|
|
{ |
|
@ -225,8 +233,10 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
|
|
|
|
|
private void JobItemStop(Guid id) |
|
|
private void JobItemStop(Guid id) |
|
|
{ |
|
|
{ |
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
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); |
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
if (entity != null) |
|
|
if (entity != null) |
|
|
{ |
|
|
{ |
|
@ -240,8 +250,10 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
|
|
|
|
|
private Guid? JobItemStart(Guid id) |
|
|
private Guid? JobItemStart(Guid id) |
|
|
{ |
|
|
{ |
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
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); |
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
if (entity != null) |
|
|
if (entity != null) |
|
|
{ |
|
|
{ |
|
@ -256,14 +268,20 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
|
|
|
|
|
|
private JobItem GetJobItem(Guid id) |
|
|
private JobItem GetJobItem(Guid id) |
|
|
{ |
|
|
{ |
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
return scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>().Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
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) |
|
|
private void JobItemHeartBeat(Guid id) |
|
|
{ |
|
|
{ |
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
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); |
|
|
var entity = db.Set<JobItem>().FirstOrDefault(o => o.Id == id); |
|
|
if (entity != null) |
|
|
if (entity != null) |
|
|
{ |
|
|
{ |
|
@ -299,8 +317,10 @@ public class JobHostdService : BackgroundService, IApplicationService |
|
|
protected override Task ExecuteAsync(CancellationToken stoppingToken) |
|
|
protected override Task ExecuteAsync(CancellationToken stoppingToken) |
|
|
{ |
|
|
{ |
|
|
this._stoppingToken = stoppingToken; |
|
|
this._stoppingToken = stoppingToken; |
|
|
using var scope = this._serviceProvider.CreateScope(); |
|
|
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService"); |
|
|
var db = scope.ServiceProvider.GetRequiredService<SettleAccountDbContext>(); |
|
|
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(); |
|
|
var jobs = db.Set<JobItem>().ToList(); |
|
|
jobs.ForEach(this.AddJob); |
|
|
jobs.ForEach(this.AddJob); |
|
|
return Task.CompletedTask; |
|
|
return Task.CompletedTask; |
|
|