add Job Tasks to enable the execution of adhoc asynchronous site-based workloads

This commit is contained in:
sbwalker
2026-02-19 08:23:11 -05:00
parent 13a58ed099
commit 0fd97d34d9
23 changed files with 633 additions and 252 deletions

View File

@@ -41,6 +41,7 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddScoped<ILogService, LogService>();
services.AddScoped<IJobService, JobService>();
services.AddScoped<IJobLogService, JobLogService>();
services.AddScoped<IJobTaskService, JobTaskService>();
services.AddScoped<INotificationService, Oqtane.Services.NotificationService>();
services.AddScoped<IFolderService, FolderService>();
services.AddScoped<IFileService, FileService>();

View File

@@ -1,7 +1,7 @@
@namespace Oqtane.Modules.Admin.GlobalReplace
@using System.Text.Json
@inherits ModuleBase
@inject ISettingService SettingService
@inject IJobTaskService JobTaskService
@inject IStringLocalizer<Index> Localizer
@inject IStringLocalizer<SharedResources> SharedLocalizer
@@ -97,9 +97,9 @@
Content = bool.Parse(_content)
};
var settings = await SettingService.GetSiteSettingsAsync(PageState.Site.SiteId);
settings = SettingService.SetSetting(settings, "GlobalReplace_" + DateTime.UtcNow.ToString("yyyyMMddHHmmss"), JsonSerializer.Serialize(replace));
await SettingService.UpdateSiteSettingsAsync(settings, PageState.Site.SiteId);
var jobTask = new JobTask(PageState.Site.SiteId, "Global Replace", "Oqtane.Infrastructure.GlobalReplaceTask, Oqtane.Server", JsonSerializer.Serialize(replace));
await JobTaskService.AddJobTaskAsync(jobTask);
AddModuleMessage(Localizer["Success.Save"], MessageType.Success);
}
else

View File

@@ -1,7 +1,7 @@
@namespace Oqtane.Modules.Admin.Users
@inherits ModuleBase
@inject NavigationManager NavigationManager
@inject IUserService UserService
@inject IJobTaskService JobTaskService
@inject IStringLocalizer<Users> Localizer
@inject IStringLocalizer<SharedResources> SharedLocalizer
@@ -43,17 +43,9 @@
var fileid = _filemanager.GetFileId();
if (fileid != -1)
{
ShowProgressIndicator();
var results = await UserService.ImportUsersAsync(PageState.Site.SiteId, fileid, bool.Parse(_notify));
if (bool.Parse(results["Success"]))
{
AddModuleMessage(string.Format(Localizer["Message.Import.Success"], results["Users"]), MessageType.Success);
}
else
{
AddModuleMessage(Localizer["Message.Import.Failure"], MessageType.Error);
}
HideProgressIndicator();
var jobTask = new JobTask(PageState.Site.SiteId, "Import Users", "Oqtane.Infrastructure.ImportUsersTask, Oqtane.Server", $"{fileid}:{_notify}");
await JobTaskService.AddJobTaskAsync(jobTask);
AddModuleMessage(Localizer["Message.Import.Success"], MessageType.Success);
}
else
{

View File

@@ -154,7 +154,7 @@
<value>Specify if module properties should be updated (ie. title, header, footer)</value>
</data>
<data name="Success.Save" xml:space="preserve">
<value>Your Global Replace Request Has Been Submitted And Will Be Executed Shortly</value>
<value>Your Global Replace Request Has Been Submitted And Will Be Executed Shortly. Please Be Patient.</value>
</data>
<data name="Error.Save" xml:space="preserve">
<value>Error Saving Global Replace</value>

View File

@@ -129,11 +129,8 @@
<data name="Import" xml:space="preserve">
<value>Import</value>
</data>
<data name="Message.Import.Failure" xml:space="preserve">
<value>User Import Failed. Please Review Your Event Log For More Detailed Information.</value>
</data>
<data name="Message.Import.Success" xml:space="preserve">
<value>User Import Successful. {0} Users Imported.</value>
<value>Your User Import Request Has Been Submitted And Will Be Executed Shortly. Please Be Patient.</value>
</data>
<data name="Message.Import.Validation" xml:space="preserve">
<value>You Must Specify A User File For Import</value>

View File

@@ -0,0 +1,46 @@
using Oqtane.Models;
using System.Threading.Tasks;
using System.Net.Http;
using Oqtane.Documentation;
using Oqtane.Shared;
namespace Oqtane.Services
{
/// <summary>
/// Service to manage tasks (<see cref="JobTask"/>)
/// </summary>
public interface IJobTaskService
{
/// <summary>
/// Return a specific task
/// </summary>
/// <param name="jobTaskId"></param>
/// <returns></returns>
Task<JobTask> GetJobTaskAsync(int jobTaskId);
/// <summary>
/// Adds a new task
/// </summary>
/// <param name="jobTask"></param>
/// <returns></returns>
Task<JobTask> AddJobTaskAsync(JobTask jobTask);
}
[PrivateApi("Don't show in the documentation, as everything should use the Interface")]
public class JobTaskService : ServiceBase, IJobTaskService
{
public JobTaskService(HttpClient http, SiteState siteState) : base(http, siteState) { }
private string Apiurl => CreateApiUrl("JobTask");
public async Task<JobTask> GetJobTaskAsync(int jobTaskId)
{
return await GetJsonAsync<JobTask>($"{Apiurl}/{jobTaskId}");
}
public async Task<JobTask> AddJobTaskAsync(JobTask jobTask)
{
return await PostJsonAsync<JobTask>(Apiurl, jobTask);
}
}
}

View File

@@ -161,15 +161,6 @@ namespace Oqtane.Services
/// <returns></returns>
Task<string> GetPasswordRequirementsAsync(int siteId);
/// <summary>
/// Bulk import of users
/// </summary>
/// <param name="siteId">ID of a <see cref="Site"/></param>
/// <param name="fileId">ID of a <see cref="File"/></param>
/// <param name="notify">Indicates if new users should be notified by email</param>
/// <returns></returns>
Task<Dictionary<string, string>> ImportUsersAsync(int siteId, int fileId, bool notify);
/// <summary>
/// Get passkeys for a user
/// </summary>
@@ -351,11 +342,6 @@ namespace Oqtane.Services
return string.Format(passwordValidationCriteriaTemplate, minimumlength, uniquecharacters, digitRequirement, uppercaseRequirement, lowercaseRequirement, punctuationRequirement);
}
public async Task<Dictionary<string, string>> ImportUsersAsync(int siteId, int fileId, bool notify)
{
return await PostJsonAsync<Dictionary<string, string>>($"{Apiurl}/import?siteid={siteId}&fileid={fileId}&notify={notify}", null);
}
public async Task<List<UserPasskey>> GetPasskeysAsync(int userId)
{
return await GetJsonAsync<List<UserPasskey>>($"{Apiurl}/passkey?id={userId}");