added support scheduler backup request handling
This commit is contained in:
parent
3513342087
commit
b5b8b1edf0
4
build/run/BackupBackgroundTasks.bat
Normal file
4
build/run/BackupBackgroundTasks.bat
Normal file
@ -0,0 +1,4 @@
|
||||
@echo off
|
||||
|
||||
PUSHD %~dp0..\..
|
||||
set servicepath=%cd%\common\services\ASC.Data.Backup.BackgroundTasks\bin\Debug\ASC.Data.Backup.BackgroundTasks.exe urls=http://0.0.0.0:5013 $STORAGE_ROOT=%cd%\Data log:dir=%cd%\Logs log:name=backup.backgroundtasks pathToConf=%cd%\config core:products:folder=%cd%\products
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.EventBus.Events;
|
||||
|
||||
@ -12,14 +11,24 @@ public record BackupRequestIntegrationEvent : IntegrationEvent
|
||||
int tenantId,
|
||||
Guid createBy,
|
||||
Dictionary<string, string> storageParams,
|
||||
bool backupMail) : base(createBy, tenantId)
|
||||
bool backupMail,
|
||||
bool isScheduled = false,
|
||||
int backupsStored = 0,
|
||||
string storageBasePath = "") : base(createBy, tenantId)
|
||||
{
|
||||
StorageType = storageType;
|
||||
StorageParams = storageParams;
|
||||
BackupMail = backupMail;
|
||||
IsScheduled = isScheduled;
|
||||
BackupsStored = backupsStored;
|
||||
StorageBasePath = storageBasePath;
|
||||
}
|
||||
|
||||
public BackupStorageType StorageType { get; private init; }
|
||||
public Dictionary<string, string> StorageParams { get; private init; }
|
||||
public bool BackupMail { get; private init; }
|
||||
public bool IsScheduled { get; private init; }
|
||||
public int BackupsStored { get; private init; }
|
||||
public string StorageBasePath { get; private init; }
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
<RazorCompileOnBuild>false</RazorCompileOnBuild>
|
||||
<GenerateMvcApplicationPartsAssemblyAttributes>false</GenerateMvcApplicationPartsAssemblyAttributes>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
|
@ -1,19 +1,17 @@
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.IO;
|
||||
global using System.Linq;
|
||||
global using System.Runtime.InteropServices;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
|
||||
global using System.Runtime.InteropServices;
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Common;
|
||||
global using ASC.Common.Caching;
|
||||
global using ASC.Common.Logging;
|
||||
global using ASC.Common.Utils;
|
||||
global using ASC.Core;
|
||||
global using ASC.Core.Billing;
|
||||
global using ASC.Core.Common.Hosting;
|
||||
global using ASC.Core.Common.Hosting.Interfaces;
|
||||
global using ASC.Data.Backup.BackgroundTasks;
|
||||
global using ASC.Data.Backup.Contracts;
|
||||
global using ASC.Data.Backup.Core.IntegrationEvents.Events;
|
||||
global using ASC.Data.Backup.IntegrationEvents.EventHandling;
|
||||
global using ASC.Data.Backup.Services;
|
||||
global using ASC.Data.Backup.Storage;
|
||||
@ -29,6 +27,7 @@ global using Microsoft.AspNetCore.Hosting;
|
||||
global using Microsoft.Extensions.Configuration;
|
||||
global using Microsoft.Extensions.DependencyInjection;
|
||||
global using Microsoft.Extensions.Hosting;
|
||||
global using Microsoft.Extensions.Hosting.WindowsServices;
|
||||
global using Microsoft.Extensions.Options;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Core.Common.Hosting.Interfaces;
|
||||
|
||||
global using Newtonsoft.Json;
|
||||
|
@ -1,31 +1,29 @@
|
||||
using ASC.Core;
|
||||
using ASC.Data.Backup.Core.IntegrationEvents.Events;
|
||||
using ASC.EventBus.Exceptions;
|
||||
|
||||
namespace ASC.Data.Backup.IntegrationEvents.EventHandling;
|
||||
namespace ASC.Data.Backup.IntegrationEvents.EventHandling;
|
||||
|
||||
[Scope]
|
||||
public class BackupRequesteIntegrationEventHandler : IIntegrationEventHandler<BackupRequestIntegrationEvent>
|
||||
public class BackupRequestIntegrationEventHandler : IIntegrationEventHandler<BackupRequestIntegrationEvent>
|
||||
{
|
||||
private readonly BackupAjaxHandler _backupAjaxHandler;
|
||||
private readonly ILog _logger;
|
||||
private readonly TenantManager _tenantManager;
|
||||
private readonly SecurityContext _securityContext;
|
||||
private readonly AuthManager _authManager;
|
||||
private readonly BackupWorker _backupWorker;
|
||||
|
||||
public BackupRequesteIntegrationEventHandler(
|
||||
public BackupRequestIntegrationEventHandler(
|
||||
BackupAjaxHandler backupAjaxHandler,
|
||||
IOptionsMonitor<ILog> logger,
|
||||
TenantManager tenantManager,
|
||||
SecurityContext securityContext,
|
||||
AuthManager authManager
|
||||
)
|
||||
AuthManager authManager,
|
||||
BackupWorker backupWorker)
|
||||
{
|
||||
_tenantManager = tenantManager;
|
||||
_authManager = authManager;
|
||||
_securityContext = securityContext;
|
||||
_backupAjaxHandler = backupAjaxHandler;
|
||||
_logger = logger.CurrentValue;
|
||||
_logger = logger.CurrentValue;
|
||||
_backupWorker = backupWorker;
|
||||
}
|
||||
|
||||
public async Task Handle(BackupRequestIntegrationEvent @event)
|
||||
@ -36,11 +34,23 @@ public class BackupRequesteIntegrationEventHandler : IIntegrationEventHandler<Ba
|
||||
|
||||
_securityContext.AuthenticateMeWithoutCookie(_authManager.GetAccountByID(@event.TenantId, @event.CreateBy));
|
||||
|
||||
_backupAjaxHandler.StartBackup(@event.StorageType, @event.StorageParams, @event.BackupMail);
|
||||
|
||||
throw new IntegrationEventRejectExeption("Backup service is very busy");
|
||||
if (@event.IsScheduled)
|
||||
{
|
||||
_backupWorker.StartScheduledBackup(new EF.Model.BackupSchedule
|
||||
{
|
||||
BackupMail = @event.BackupMail,
|
||||
BackupsStored = @event.BackupsStored,
|
||||
StorageBasePath = @event.StorageBasePath,
|
||||
StorageParams = JsonConvert.SerializeObject(@event.StorageParams),
|
||||
StorageType = @event.StorageType,
|
||||
TenantId = @event.TenantId
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_backupAjaxHandler.StartBackup(@event.StorageType, @event.StorageParams, @event.BackupMail);
|
||||
}
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
}
|
||||
}
|
@ -1,9 +1,4 @@
|
||||
using ASC.Data.Backup.BackgroundTasks;
|
||||
using ASC.Data.Backup.Core.IntegrationEvents.Events;
|
||||
|
||||
using Microsoft.Extensions.Hosting.WindowsServices;
|
||||
|
||||
var options = new WebApplicationOptions
|
||||
var options = new WebApplicationOptions
|
||||
{
|
||||
Args = args,
|
||||
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
|
||||
@ -87,7 +82,7 @@ startup.Configure(app, app.Environment);
|
||||
|
||||
var eventBus = ((IApplicationBuilder)app).ApplicationServices.GetRequiredService<IEventBus>();
|
||||
|
||||
eventBus.Subscribe<BackupRequestIntegrationEvent, BackupRequesteIntegrationEventHandler>();
|
||||
eventBus.Subscribe<BackupRequestIntegrationEvent, BackupRequestIntegrationEventHandler>();
|
||||
|
||||
app.Run();
|
||||
|
||||
|
@ -23,8 +23,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using ASC.Core.Common.Hosting;
|
||||
|
||||
namespace ASC.Data.Backup.Services;
|
||||
|
||||
[Singletone]
|
||||
|
@ -23,9 +23,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
using ASC.Core.Common.Hosting;
|
||||
using ASC.ElasticSearch.Service;
|
||||
|
||||
namespace ASC.Data.Backup.Services;
|
||||
|
||||
[Singletone]
|
||||
@ -34,7 +31,6 @@ public sealed class BackupSchedulerService : BackgroundService
|
||||
private readonly TimeSpan _backupSchedulerPeriod;
|
||||
private readonly ILog _logger;
|
||||
|
||||
private readonly BackupWorker _backupWorker;
|
||||
private readonly CoreBaseSettings _coreBaseSettings;
|
||||
private readonly IServiceScopeFactory _scopeFactory;
|
||||
private readonly IEventBus _eventBus;
|
||||
@ -50,7 +46,6 @@ public sealed class BackupSchedulerService : BackgroundService
|
||||
{
|
||||
_logger = options.CurrentValue;
|
||||
_coreBaseSettings = coreBaseSettings;
|
||||
_backupWorker = backupWorker;
|
||||
_backupSchedulerPeriod = configuration.GetSetting<BackupSettings>("backup").Scheduler.Period;
|
||||
_scopeFactory = scopeFactory;
|
||||
_eventBus = eventBus;
|
||||
@ -120,7 +115,16 @@ public sealed class BackupSchedulerService : BackgroundService
|
||||
|
||||
_logger.DebugFormat("Start scheduled backup: {0}, {1}, {2}, {3}", schedule.TenantId, schedule.BackupMail, schedule.StorageType, schedule.StorageBasePath);
|
||||
|
||||
_backupWorker.StartScheduledBackup(schedule);
|
||||
_eventBus.Publish(new BackupRequestIntegrationEvent(
|
||||
tenantId: schedule.TenantId,
|
||||
storageBasePath: schedule.StorageBasePath,
|
||||
storageParams: JsonConvert.DeserializeObject<Dictionary<string,string>>(schedule.StorageParams),
|
||||
storageType: schedule.StorageType,
|
||||
backupMail: schedule.BackupMail,
|
||||
createBy: ASC.Core.Configuration.Constants.CoreSystem.ID,
|
||||
isScheduled: true,
|
||||
backupsStored: schedule.BackupsStored
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -41,7 +41,8 @@ public class Startup : BaseStartup
|
||||
|
||||
NotifyConfigurationExtension.Register(DIHelper);
|
||||
|
||||
DIHelper.TryAdd<BackupRequesteIntegrationEventHandler>();
|
||||
DIHelper.TryAdd<Schedule>();
|
||||
DIHelper.TryAdd<BackupRequestIntegrationEventHandler>();
|
||||
|
||||
DIHelper.TryAdd<BackupListenerService>();
|
||||
services.AddHostedService<BackupListenerService>();
|
||||
|
@ -43,8 +43,6 @@ public class Startup : BaseStartup
|
||||
DIHelper.TryAdd<RestoreProgressItem>();
|
||||
DIHelper.TryAdd<TransferProgressItem>();
|
||||
|
||||
DIHelper.TryAdd<Schedule>();
|
||||
|
||||
DIHelper.TryAdd<BackupController>();
|
||||
|
||||
NotifyConfigurationExtension.Register(DIHelper);
|
||||
|
Loading…
Reference in New Issue
Block a user