-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathQueueOperationServices.cs
40 lines (34 loc) · 1.25 KB
/
QueueOperationServices.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using AiServer.ServiceInterface.AppDb;
using ServiceStack;
using ServiceStack.Data;
using AiServer.ServiceModel;
using ServiceStack.Jobs;
using ServiceStack.OrmLite;
namespace AiServer.ServiceInterface;
public class QueueOperationServices(AppData appData, IDbConnectionFactory dbFactory, IBackgroundJobs jobs)
: Service
{
public async Task<object> Any(Reload request)
{
using var db = await dbFactory.OpenDbConnectionAsync();
appData.Reload(db);
return new EmptyResponse();
}
public object Any(ChangeAiProviderStatus request)
{
var apiProvider = appData.AiProviders.FirstOrDefault(x => x.Name == request.Provider)
?? throw HttpError.NotFound("AiProvider not found");
DateTime? offlineDate = request.Online ? null : DateTime.UtcNow;
apiProvider.OfflineDate = offlineDate;
jobs.RunCommand<ChangeProviderStatusCommand>(new ChangeProviderStatus {
Name = apiProvider.Name,
OfflineDate = offlineDate,
});
return new StringResponse
{
Result = offlineDate == null
? $"{apiProvider.Name} is back online"
: $"{apiProvider.Name} was taken offline"
};
}
}