Skip to content

Commit

Permalink
Move Scheduled Task to Grand.Module.ScheduledTasks (#530)
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak authored Nov 26, 2024
1 parent a23f2ff commit 44b0ffe
Show file tree
Hide file tree
Showing 57 changed files with 191 additions and 382 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aspnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Grand.Business.Storage Unit Tests
run: dotnet test ./src/Tests/Grand.Business.Storage.Tests/Grand.Business.Storage.Tests.csproj
- name: Grand.Business.System Unit Tests
run: dotnet test ./src/Tests/Grand.Business.System.Tests/Grand.Business.System.Tests.csproj
run: dotnet test ./src/Tests/Grand.Modules.Tests/Grand.Modules.Tests.csproj
- name: Grand.Business.Data Unit Tests
run: dotnet test ./src/Tests/Grand.Data.Tests/Grand.Data.Tests.csproj
- name: Grand.Domain.Domain.Tests Unit Tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/grandnode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Grand.Business.Storage Unit Tests
run: dotnet test ./src/Tests/Grand.Business.Storage.Tests/Grand.Business.Storage.Tests.csproj
- name: Grand.Business.System Unit Tests
run: dotnet test ./src/Tests/Grand.Business.System.Tests/Grand.Business.System.Tests.csproj
run: dotnet test ./src/Tests/Grand.Modules.Tests/Grand.Modules.Tests.csproj
- name: Grand.Business.Data Unit Tests
run: dotnet test ./src/Tests/Grand.Data.Tests/Grand.Data.Tests.csproj
- name: Grand.Domain.Domain.Tests Unit Tests
Expand Down
16 changes: 8 additions & 8 deletions GrandNode.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.Storage", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.Catalog", "src\Business\Grand.Business.Catalog\Grand.Business.Catalog.csproj", "{6925EF20-C289-482E-855E-DAFCE62BE16A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.System", "src\Business\Grand.Business.System\Grand.Business.System.csproj", "{9B4BF192-F99A-4969-8472-A0C36B615DB3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.Authentication", "src\Business\Grand.Business.Authentication\Grand.Business.Authentication.csproj", "{6F9902AA-DBCE-4BB8-AEBE-47264A10D933}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.Messages", "src\Business\Grand.Business.Messages\Grand.Business.Messages.csproj", "{D2E8AC42-2751-4AF9-87E4-54A8B2034360}"
Expand Down Expand Up @@ -89,7 +87,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.Messages.Tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.Storage.Tests", "src\Tests\Grand.Business.Storage.Tests\Grand.Business.Storage.Tests.csproj", "{E0CDC8F3-2F79-40ED-AD7C-EF3F7B056BEA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.System.Tests", "src\Tests\Grand.Business.System.Tests\Grand.Business.System.Tests.csproj", "{3CCCC424-B13F-479B-94A2-A0A6B05C0858}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Modules.Tests", "src\Tests\Grand.Modules.Tests\Grand.Modules.Tests.csproj", "{3CCCC424-B13F-479B-94A2-A0A6B05C0858}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Grand.Business.Checkout.Tests", "src\Tests\Grand.Business.Checkout.Tests\Grand.Business.Checkout.Tests.csproj", "{B34CA673-578B-46D8-BEC0-2C32BF6997F9}"
EndProject
Expand Down Expand Up @@ -139,6 +137,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grand.Module.Migration", "s
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grand.Module.Api", "src\Modules\Grand.Module.Api\Grand.Module.Api.csproj", "{E0B26803-010B-4198-8016-002242076B61}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Grand.Module.ScheduledTasks", "src\Modules\Grand.Module.ScheduledTasks\Grand.Module.ScheduledTasks.csproj", "{136F1E35-8B20-465C-8D42-30A5A0D0DA1F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -185,10 +185,6 @@ Global
{6925EF20-C289-482E-855E-DAFCE62BE16A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6925EF20-C289-482E-855E-DAFCE62BE16A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6925EF20-C289-482E-855E-DAFCE62BE16A}.Release|Any CPU.Build.0 = Release|Any CPU
{9B4BF192-F99A-4969-8472-A0C36B615DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B4BF192-F99A-4969-8472-A0C36B615DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B4BF192-F99A-4969-8472-A0C36B615DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B4BF192-F99A-4969-8472-A0C36B615DB3}.Release|Any CPU.Build.0 = Release|Any CPU
{6F9902AA-DBCE-4BB8-AEBE-47264A10D933}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F9902AA-DBCE-4BB8-AEBE-47264A10D933}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F9902AA-DBCE-4BB8-AEBE-47264A10D933}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -368,6 +364,10 @@ Global
{E0B26803-010B-4198-8016-002242076B61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0B26803-010B-4198-8016-002242076B61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0B26803-010B-4198-8016-002242076B61}.Release|Any CPU.Build.0 = Release|Any CPU
{136F1E35-8B20-465C-8D42-30A5A0D0DA1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{136F1E35-8B20-465C-8D42-30A5A0D0DA1F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{136F1E35-8B20-465C-8D42-30A5A0D0DA1F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{136F1E35-8B20-465C-8D42-30A5A0D0DA1F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -383,7 +383,6 @@ Global
{35427306-7271-456A-A337-F7D7E79FB027} = {6EAC4D2C-4A86-4C9F-8427-CB374F69F08C}
{B93A72CF-18A9-40E1-8902-63EEA6094905} = {6EAC4D2C-4A86-4C9F-8427-CB374F69F08C}
{6925EF20-C289-482E-855E-DAFCE62BE16A} = {6EAC4D2C-4A86-4C9F-8427-CB374F69F08C}
{9B4BF192-F99A-4969-8472-A0C36B615DB3} = {6EAC4D2C-4A86-4C9F-8427-CB374F69F08C}
{6F9902AA-DBCE-4BB8-AEBE-47264A10D933} = {6EAC4D2C-4A86-4C9F-8427-CB374F69F08C}
{D2E8AC42-2751-4AF9-87E4-54A8B2034360} = {6EAC4D2C-4A86-4C9F-8427-CB374F69F08C}
{1A6A0104-F610-4DD3-88BE-C4029034E5DA} = {BF4543A8-0731-4FDD-BB6B-0ADB9561F981}
Expand Down Expand Up @@ -429,6 +428,7 @@ Global
{62460E0C-D4D1-4606-9716-965267B77BA3} = {583FFBBD-421C-4FB7-BBDA-F9CAF35A354A}
{75F9D855-026B-4BCB-90CE-3800F02FA0A7} = {583FFBBD-421C-4FB7-BBDA-F9CAF35A354A}
{E0B26803-010B-4198-8016-002242076B61} = {583FFBBD-421C-4FB7-BBDA-F9CAF35A354A}
{136F1E35-8B20-465C-8D42-30A5A0D0DA1F} = {583FFBBD-421C-4FB7-BBDA-F9CAF35A354A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {88B478F4-FD3B-4C24-9E84-4FAAF0254397}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public interface IScheduleTaskService
/// <summary>
/// Gets a task by its type
/// </summary>
/// <param name="type">Task type</param>
/// <param name="name">Task name</param>
/// <returns>Task</returns>
Task<ScheduleTask> GetTaskByType(string type);
Task<ScheduleTask> GetTaskByName(string name);

/// <summary>
/// Gets all tasks
Expand Down

This file was deleted.

37 changes: 0 additions & 37 deletions src/Business/Grand.Business.System/Startup/StartupApplication.cs

This file was deleted.

3 changes: 1 addition & 2 deletions src/Core/Grand.Domain/Tasks/ScheduleTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

public class ScheduleTask : BaseEntity
{
public string ScheduleTaskName { get; set; }
public string Type { get; set; }
public string ScheduleTaskName { get; set; }
public bool Enabled { get; set; }
public bool StopOnError { get; set; }
public DateTime? LastStartUtc { get; set; }
Expand Down
5 changes: 0 additions & 5 deletions src/Core/Grand.Infrastructure/Configuration/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ namespace Grand.Infrastructure.Configuration;
/// </summary>
public class AppConfig
{
/// <summary>
/// Indicates whether we should Disable HostedService - BackgroundServiceTask
/// </summary>
public bool DisableHostedService { get; set; }

/// <summary>
/// A value indicating whether SEO friendly URLs with multiple languages are enabled
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,42 @@ protected virtual Task InstallScheduleTasks()
var tasks = new List<ScheduleTask> {
new() {
ScheduleTaskName = "Send emails",
Type =
"Grand.Business.System.Services.BackgroundServices.ScheduleTasks.QueuedMessagesSendScheduleTask, Grand.Business.System",
Enabled = true,
StopOnError = false,
TimeInterval = 1
},
new() {
ScheduleTaskName = "Delete guests",
Type =
"Grand.Business.System.Services.BackgroundServices.ScheduleTasks.DeleteGuestsScheduleTask, Grand.Business.System",
Enabled = true,
StopOnError = false,
TimeInterval = 1440
},
new() {
ScheduleTaskName = "Clear cache",
Type =
"Grand.Business.System.Services.BackgroundServices.ScheduleTasks.ClearCacheScheduleTask, Grand.Business.System",
Enabled = false,
StopOnError = false,
TimeInterval = 120
},
new() {
ScheduleTaskName = "Update currency exchange rates",
Type =
"Grand.Business.System.Services.BackgroundServices.ScheduleTasks.UpdateExchangeRateScheduleTask, Grand.Business.System",
Enabled = true,
StopOnError = false,
TimeInterval = 1440
},
new() {
ScheduleTaskName = "Generate sitemap XML file",
Type =
"Grand.Business.System.Services.BackgroundServices.ScheduleTasks.GenerateSitemapXmlTask, Grand.Business.System",
Enabled = false,
StopOnError = false,
TimeInterval = 10080
},
new() {
ScheduleTaskName = "End of the auctions",
Type =
"Grand.Business.System.Services.BackgroundServices.ScheduleTasks.EndAuctionsTask, Grand.Business.System",
Enabled = false,
StopOnError = false,
TimeInterval = 60
},
new() {
ScheduleTaskName = "Cancel unpaid and pending orders",
Type =
"Grand.Business.System.Services.BackgroundServices.ScheduleTasks.CancelOrderScheduledTask, Grand.Business.System",
Enabled = false,
StopOnError = false,
TimeInterval = 1440
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Grand.Business.Core.Interfaces.System.ScheduleTasks;
using Grand.Domain.Common;

namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks;
namespace Grand.Module.ScheduledTasks.BackgroundServices;

public class CancelOrderScheduledTask : IScheduleTask
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Grand.Business.Core.Interfaces.System.ScheduleTasks;
using Grand.Infrastructure.Caching;

namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks;
namespace Grand.Module.ScheduledTasks.BackgroundServices;

/// <summary>
/// Clear cache scheduled task implementation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Grand.Business.Core.Interfaces.System.ScheduleTasks;
using Grand.Domain.Common;

namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks;
namespace Grand.Module.ScheduledTasks.BackgroundServices;

/// <summary>
/// Represents a task for deleting guest customers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Grand.Domain.Orders;
using Microsoft.Extensions.Logging;

namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks;
namespace Grand.Module.ScheduledTasks.BackgroundServices;

/// <summary>
/// Represents a task end auctions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Grand.Business.Core.Interfaces.System.ScheduleTasks;
using MediatR;

namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks;
namespace Grand.Module.ScheduledTasks.BackgroundServices;

/// <summary>
/// Represents a task end auctions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Grand.Business.Core.Interfaces.System.ScheduleTasks;
using Microsoft.Extensions.Logging;

namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks;
namespace Grand.Module.ScheduledTasks.BackgroundServices;

/// <summary>
/// Represents a task for sending queued message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Grand.Data;
using Grand.Domain.Tasks;

namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks;
namespace Grand.Module.ScheduledTasks.BackgroundServices;

/// <summary>
/// Task service
Expand Down Expand Up @@ -35,17 +35,16 @@ public virtual Task<ScheduleTask> GetTaskById(string taskId)
}

/// <summary>
/// Gets a task by its type
/// Gets a task by its name
/// </summary>
/// <param name="type">Task type</param>
/// <returns>Task</returns>
public virtual async Task<ScheduleTask> GetTaskByType(string type)
public virtual async Task<ScheduleTask> GetTaskByName(string name)
{
if (string.IsNullOrWhiteSpace(type))
if (string.IsNullOrWhiteSpace(name))
return null;

var query = _taskRepository.Table.Where(st => st.Type == type).OrderByDescending(t => t.Id);
return await Task.FromResult(query.FirstOrDefault());
var task = _taskRepository.Table.FirstOrDefault(x => x.ScheduleTaskName == name);
return await Task.FromResult(task);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Grand.Domain.Directory;
using Grand.Domain.Tasks;

namespace Grand.Business.System.Services.BackgroundServices.ScheduleTasks;
namespace Grand.Module.ScheduledTasks.BackgroundServices;

/// <summary>
/// Represents a task for updating exchange rates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Grand.SharedKernel.Extensions;
using MediatR;

namespace Grand.Business.System.Commands.Handlers.Catalog;
namespace Grand.Module.ScheduledTasks.Commands.Handlers.Catalog;

public class
SendNotificationsToSubscribersCommandHandler : IRequestHandler<SendNotificationsToSubscribersCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Grand.Business.Core.Interfaces.Messages;
using MediatR;

namespace Grand.Business.System.Commands.Handlers.Catalog;
namespace Grand.Module.ScheduledTasks.Commands.Handlers.Catalog;

public class SendOutBidCustomerNotificationCommandHandler : IRequestHandler<SendOutBidCustomerCommand, bool>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Grand.Domain.Localization;
using MediatR;

namespace Grand.Business.System.Commands.Handlers.Catalog;
namespace Grand.Module.ScheduledTasks.Commands.Handlers.Catalog;

public class
SendQuantityBelowStoreOwnerNotificationCommandHandler : IRequestHandler<SendQuantityBelowStoreOwnerCommand, bool>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\Build\Grand.Common.props" />
<ItemGroup>
<ProjectReference Include="..\..\Core\Grand.Data\Grand.Data.csproj">
<Private>False</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="..\..\Core\Grand.Domain\Grand.Domain.csproj">
<Private>False</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="..\..\Core\Grand.Infrastructure\Grand.Infrastructure.csproj">
<Private>False</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="..\..\Core\Grand.SharedKernel\Grand.SharedKernel.csproj">
<Private>False</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
<ProjectReference Include="..\..\Business\Grand.Business.Core\Grand.Business.Core.csproj">
<Private>False</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\..\Web\Grand.Web\Modules\Grand.Module.ScheduledTasks\</OutputPath>
<OutDir>$(OutputPath)</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\..\Web\Grand.Web\Modules\Grand.Module.ScheduledTasks\</OutputPath>
<OutDir>$(OutputPath)</OutDir>
</PropertyGroup>
</Project>
Loading

0 comments on commit 44b0ffe

Please sign in to comment.