Skip to content

Commit c6fee4f

Browse files
committed
update
1 parent 1f47b91 commit c6fee4f

47 files changed

Lines changed: 9827 additions & 5848 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MyApp.AI/MyApp.AI.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

MyApp.ServiceInterface/Server/DatabaseJobs.ScheduledTasks.cs renamed to MyApp.Server/DbJobs.ScheduledTasks.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
#nullable enable
2+
#if NET6_0_OR_GREATER
13
using System.Collections.Concurrent;
24
using ServiceStack.OrmLite;
35
using Cronos;
46
using ServiceStack.Jobs;
57

68
namespace ServiceStack;
79

8-
public partial class DatabaseJobs
10+
public partial class DbJobs
911
{
1012
private ConcurrentDictionary<string, ScheduledTask> namedScheduledTasks = new();
1113
private ConcurrentDictionary<string, CronExpression> cronExpressions = new();
@@ -158,4 +160,4 @@ public void ClearScheduledTasks()
158160
cronExpressions.Clear();
159161
}
160162
}
161-
163+
#endif

MyApp.ServiceInterface/Server/DatabaseJobs.cs renamed to MyApp.Server/DbJobs.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#nullable enable
2+
#if NET6_0_OR_GREATER
13
using Microsoft.Extensions.DependencyInjection;
24
using Microsoft.Extensions.Logging;
35
using System.Collections.Concurrent;
46
using System.Data;
57
using ServiceStack.Auth;
6-
using ServiceStack.Data;
78
using ServiceStack.Host;
89
using ServiceStack.Jobs;
910
using ServiceStack.Messaging;
@@ -13,21 +14,21 @@
1314

1415
namespace ServiceStack;
1516

16-
public partial class DatabaseJobs : IBackgroundJobs
17+
public partial class DbJobs : IBackgroundJobs
1718
{
18-
readonly ILogger<DatabaseJobs> log;
19+
readonly ILogger<DbJobs> log;
1920
readonly DatabaseJobFeature feature;
2021
private IServiceProvider services;
2122
readonly IServiceScopeFactory scopeFactory;
2223
private ConcurrentDictionary<string, int> lastCommandDurations = new();
2324
private ConcurrentDictionary<string, int> lastApiDurations = new();
24-
ConcurrentDictionary<string, DatabaseJobsWorker> workers = new();
25+
ConcurrentDictionary<string, DbJobsWorker> workers = new();
2526
static ConcurrentQueue<BackgroundJobStatusUpdate> updates = new();
2627
string Table;
2728
Columns columns;
2829
private long ticks = 0;
2930

30-
public DatabaseJobs(ILogger<DatabaseJobs> log,
31+
public DbJobs(ILogger<DbJobs> log,
3132
DatabaseJobFeature feature, IServiceProvider services, IServiceScopeFactory scopeFactory)
3233
{
3334
// Need to store local references to these dependencies otherwise won't exist on BG Thread callbacks
@@ -36,7 +37,7 @@ public DatabaseJobs(ILogger<DatabaseJobs> log,
3637
this.services = services;
3738
this.scopeFactory = scopeFactory;
3839

39-
var dialect = feature.DialectProvider;
40+
var dialect = feature.Dialect;
4041
this.Table = dialect.GetQuotedTableName(typeof(BackgroundJob));
4142
this.columns = new(
4243
Logs:dialect.GetQuotedColumnName(nameof(BackgroundJob.Logs)),
@@ -898,7 +899,7 @@ public void DispatchToWorker(BackgroundJob job)
898899
if (job.Worker != null)
899900
{
900901
var worker = workers.GetOrAdd(job.Worker,
901-
_ => new DatabaseJobsWorker(this, ct, transient:false, feature.DefaultTimeoutSecs) { Name = job.Worker });
902+
_ => new DbJobsWorker(this, ct, transient:false, feature.DefaultTimeoutSecs) { Name = job.Worker });
902903
if (worker.HasJobQueued(job.Id))
903904
{
904905
var runningTime = worker.RunningTime ?? TimeSpan.Zero;
@@ -910,7 +911,7 @@ public void DispatchToWorker(BackgroundJob job)
910911
{
911912
CancelWorker(job.Worker);
912913
worker = workers.GetOrAdd(job.Worker,
913-
_ => new DatabaseJobsWorker(this, ct, transient:false, feature.DefaultTimeoutSecs) { Name = job.Worker });
914+
_ => new DbJobsWorker(this, ct, transient:false, feature.DefaultTimeoutSecs) { Name = job.Worker });
914915
}
915916
else
916917
{
@@ -923,7 +924,7 @@ public void DispatchToWorker(BackgroundJob job)
923924
else
924925
{
925926
// Otherwise invoke a new worker immediately
926-
new DatabaseJobsWorker(this, ct, transient:true, feature.DefaultTimeoutSecs).Enqueue(job);
927+
new DbJobsWorker(this, ct, transient:true, feature.DefaultTimeoutSecs).Enqueue(job);
927928
}
928929
}
929930

@@ -936,7 +937,7 @@ public void CancelWorker(string worker)
936937

937938
// Transfer jobs to new Worker before disposing
938939
var newWorker = workers.GetOrAdd(worker,
939-
_ => new DatabaseJobsWorker(this, ct, transient:false, feature.DefaultTimeoutSecs) { Name = worker });
940+
_ => new DbJobsWorker(this, ct, transient:false, feature.DefaultTimeoutSecs) { Name = worker });
940941
while (bgWorker.Queue.TryDequeue(out var job))
941942
{
942943
newWorker.Enqueue(job);
@@ -1233,3 +1234,4 @@ public void Clear()
12331234
ClearScheduledTasks();
12341235
}
12351236
}
1237+
#endif

MyApp.ServiceInterface/Server/AdminJobServices.cs renamed to MyApp.Server/DbJobsAdminServices.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
#nullable enable
2+
#if NET6_0_OR_GREATER
13
using System.Linq.Expressions;
24
using Microsoft.Extensions.Logging;
35
using ServiceStack.DataAnnotations;
4-
using ServiceStack.Host;
5-
using ServiceStack.NativeTypes;
66
using ServiceStack.OrmLite;
77
using ServiceStack.Jobs;
88

@@ -163,7 +163,7 @@ public class HourSummary
163163
public int Cancelled { get; set; }
164164
}
165165

166-
public class AdminJobServices(ILogger<AdminJobServices> log, IBackgroundJobs jobs, IAutoQueryDb autoQuery) : Service
166+
public class DbJobsAdminServices(ILogger<DbJobsAdminServices> log, IBackgroundJobs jobs, IAutoQueryDb autoQuery) : Service
167167
{
168168
private DatabaseJobFeature AssertRequiredRole()
169169
{
@@ -560,4 +560,5 @@ public static List<HourSummary> ToSummaries(this List<HourStat> hourStats)
560560
}
561561
return to;
562562
}
563-
}
563+
}
564+
#endif

MyApp.ServiceInterface/Server/DatabaseJobsExtensions.cs renamed to MyApp.Server/DbJobsExtensions.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
#nullable enable
2+
#if NET6_0_OR_GREATER
13
using Microsoft.Extensions.DependencyInjection;
24
using ServiceStack.Data;
35

46
namespace ServiceStack;
57

6-
public static class DatabaseJobsExtensions
8+
public static class DbJobsExtensions
79
{
810
// Admin UI requires AutoQuery functionality
911
public static void RegisterAutoQueryDbIfNotExists(this AutoQueryFeature feature)
1012
{
11-
ServiceStackHost.GlobalAfterConfigureServices.Add(c =>
13+
ServiceStackHost.GlobalAfterConfigureServices.Add(services =>
1214
{
13-
if (!c.Exists<IAutoQueryDb>())
15+
if (!services.Exists<IAutoQueryDb>())
1416
{
15-
c.AddSingleton<IAutoQueryDb>(c =>
17+
services.AddSingleton<IAutoQueryDb>(c =>
1618
feature.CreateAutoQueryDb(c.GetService<IDbConnectionFactory>()));
1719
}
1820
});
1921
}
20-
}
22+
}
23+
#endif

MyApp.ServiceInterface/Server/DatabaseJobsFeature.cs renamed to MyApp.Server/DbJobsFeature.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if NET6_0_OR_GREATER
12
using Microsoft.Extensions.DependencyInjection;
23
using System.Data;
34
using Microsoft.Extensions.Logging;
@@ -15,12 +16,13 @@ public class DatabaseJobFeature : IPlugin, Model.IHasStringId, IConfigureService
1516
/// Limit API access to users in role
1617
/// </summary>
1718
public string AccessRole { get; set; } = RoleNames.Admin;
18-
public DbJobsProvider DbProvider { get; set; }
19-
public Action<IOrmLiteDialectProvider>? ConfigureDialectProvider { get; set; }
20-
public IOrmLiteDialectProvider DialectProvider => DbProvider.Dialect;
19+
public IDbConnectionFactory DbFactory { get; set; } = null!;
20+
public string? NamedConnection { get; set; }
21+
public DbJobsProvider DbProvider { get; set; } = null!;
22+
public IOrmLiteDialectProvider Dialect => DbProvider.Dialect;
23+
public Action<IOrmLiteDialectProvider>? ConfigureDialect { get; set; }
2124
public bool AutoInitSchema { get; set; } = true;
2225
public bool EnableAdmin { get; set; } = true;
23-
public IDbConnectionFactory DbFactory { get; set; } = null!;
2426
public IAppHostNetCore AppHost { get; set; } = null!;
2527
public CommandsFeature CommandsFeature { get; set; } = null!;
2628
public IBackgroundJobs Jobs { get; set; } = null!;
@@ -45,16 +47,16 @@ DatabaseJobFeature Resolve(IServiceProvider services)
4547
public void Configure(IServiceCollection services)
4648
{
4749
services.AddSingleton(this);
48-
services.AddSingleton<IBackgroundJobs>(c => new DatabaseJobs(
49-
c.GetRequiredService<ILogger<DatabaseJobs>>(),
50+
services.AddSingleton<IBackgroundJobs>(c => new DbJobs(
51+
c.GetRequiredService<ILogger<DbJobs>>(),
5052
Resolve(c),
5153
c,
5254
c.GetRequiredService<IServiceScopeFactory>()
5355
));
5456

5557
if (EnableAdmin)
5658
{
57-
services.RegisterService<AdminJobServices>();
59+
services.RegisterService<DbJobsAdminServices>();
5860
AutoQueryFeature ??= new() { MaxLimit = 1000 };
5961
AutoQueryFeature.RegisterAutoQueryDbIfNotExists();
6062
}
@@ -64,8 +66,8 @@ protected void Init(IServiceProvider services)
6466
{
6567
DbFactory ??= services.GetService<IDbConnectionFactory>()
6668
?? throw new Exception($"{nameof(IDbConnectionFactory)} is not registered");
67-
DbProvider ??= DbJobsProvider.Create(DbFactory);
68-
var dateConverter = DialectProvider.GetDateTimeConverter();
69+
DbProvider ??= DbJobsProvider.Create(DbFactory, NamedConnection);
70+
var dateConverter = Dialect.GetDateTimeConverter();
6971
if (dateConverter.DateStyle == DateTimeKind.Unspecified)
7072
dateConverter.DateStyle = DateTimeKind.Utc;
7173
}
@@ -80,7 +82,7 @@ public void Register(IAppHost appHost)
8082
Jobs ??= services.GetService<IBackgroundJobs>()
8183
?? throw new Exception($"{nameof(IBackgroundJobs)} is not registered");
8284

83-
ConfigureDialectProvider?.Invoke(DbProvider.Dialect);
85+
ConfigureDialect?.Invoke(DbProvider.Dialect);
8486

8587
AppHost ??= (IAppHostNetCore)appHost;
8688

@@ -115,3 +117,4 @@ public void BeforePluginsLoaded(IAppHost appHost)
115117

116118
public IServiceProvider Services => AppHost!.App.ApplicationServices;
117119
}
120+
#endif

0 commit comments

Comments
 (0)