Skip to content

Commit

Permalink
Feature/cron (#299)
Browse files Browse the repository at this point in the history
* Update nugets and docs for cron jobs

* Initial implementation of cron jobs plugin
  • Loading branch information
k3ldar authored Aug 27, 2024
1 parent c33a10a commit 6a08e0a
Show file tree
Hide file tree
Showing 62 changed files with 2,872 additions and 343 deletions.
6 changes: 6 additions & 0 deletions AspNetCore.PluginManager.Solution.sln
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATE", "ISSUE_TEMPLATE", "{054AB9E6-B61B-416E-9680-8F470C38D767}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cron.Plugin", "Plugins\Cron.Plugin\Cron.Plugin.csproj", "{B0503DFC-C6A5-4D44-9B66-F9FB3786E7DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -297,6 +299,10 @@ Global
{33E06D80-EEED-491E-A212-7C5E6688A37D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{33E06D80-EEED-491E-A212-7C5E6688A37D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{33E06D80-EEED-491E-A212-7C5E6688A37D}.Release|Any CPU.Build.0 = Release|Any CPU
{B0503DFC-C6A5-4D44-9B66-F9FB3786E7DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0503DFC-C6A5-4D44-9B66-F9FB3786E7DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0503DFC-C6A5-4D44-9B66-F9FB3786E7DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0503DFC-C6A5-4D44-9B66-F9FB3786E7DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions DAL/PluginManager.DAL.TextFiles/Internal/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ internal static class Constants
public const string TableNameFAQ = "FAQGroups";
public const string TableNameFAQItem = "FAQItems";

public const string TableNameCronJobs = "CronJobs";

public const string DomainDownloads = "Downloads";
public const string TableNameDownloadCategories = "DownloadCategories";
public const string TableNameDownloadItems = "DownloadItems";
Expand Down
6 changes: 5 additions & 1 deletion DAL/PluginManager.DAL.TextFiles/PluginInitialisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
using Middleware.Accounts;
using Middleware.DynamicContent;
using Middleware.Helpdesk;
using Middleware.Interfaces;

using PluginManager.Abstractions;
using PluginManager.DAL.TextFiles.Providers;
Expand Down Expand Up @@ -92,6 +91,8 @@ public void AfterConfigure(in IApplicationBuilder app)
_ = app.ApplicationServices.GetService<ISimpleDBOperations<ContentPageDataRow>>();
_ = app.ApplicationServices.GetService<ISimpleDBOperations<ContentPageItemDataRow>>();

_ = app.ApplicationServices.GetService<ISimpleDBOperations<CronJobDataRow>>();

_ = app.ApplicationServices.GetService<ISimpleDBOperations<ExternalUsersDataRow>>();

_ = app.ApplicationServices.GetService<ISimpleDBOperations<FeedbackDataRow>>();
Expand Down Expand Up @@ -176,6 +177,8 @@ public void BeforeConfigureServices(in IServiceCollection services)
services.AddSingleton(typeof(TableRowDefinition), typeof(ContentPageDataRow));
services.AddSingleton(typeof(TableRowDefinition), typeof(ContentPageItemDataRow));

services.AddSingleton(typeof(TableRowDefinition), typeof(CronJobDataRow));

services.AddSingleton(typeof(TableRowDefinition), typeof(ExternalUsersDataRow));

services.AddSingleton(typeof(TableRowDefinition), typeof(FeedbackDataRow));
Expand Down Expand Up @@ -236,6 +239,7 @@ public void BeforeConfigureServices(in IServiceCollection services)
services.AddSingleton<IBlogProvider, BlogProvider>();
services.AddSingleton<IClaimsProvider, ClaimsProvider>();
services.AddSingleton<ICountryProvider, CountryProvider>();
services.AddSingleton<ICronJobProvider, CronJobProvider>();
services.AddSingleton<IDownloadProvider, DownloadProvider>();
services.AddSingleton<IDynamicContentProvider, DynamicContentProvider>();
services.AddSingleton<IHelpdeskProvider, HelpdeskProvider>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="readme.md" Pack="true" PackagePath=""/>
<None Include="readme.md" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
Expand Down
78 changes: 78 additions & 0 deletions DAL/PluginManager.DAL.TextFiles/Providers/CronJobProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* .Net Core Plugin Manager is distributed under the GNU General Public License version 3 and
* is also available under alternative licenses negotiated directly with Simon Carter.
* If you obtained Service Manager under the GPL, then the GPL applies to all loadable
* Service Manager modules used on your system as well. The GPL (version 3) is
* available at https://opensource.org/licenses/GPL-3.0
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* The Original Code was created by Simon Carter (s1cart3r@gmail.com)
*
* Copyright (c) 2024 Simon Carter. All Rights Reserved.
*
* Product: PluginManager.DAL.TextFiles
*
* File: CronProvider.cs
*
* Purpose: ICronProvider for text based storage
*
* Date Name Reason
* 25/08/2024 Simon Carter Initially Created
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
using Middleware;

using PluginManager.DAL.TextFiles.Tables;

using SharedPluginFeatures;

using SimpleDB;

namespace PluginManager.DAL.TextFiles.Providers
{
internal sealed class CronJobProvider : ICronJobProvider
{
private readonly ISimpleDBOperations<CronJobDataRow> _cronJobSettings;

public CronJobProvider(ISimpleDBOperations<CronJobDataRow> cronJobSettings)
{
_cronJobSettings = cronJobSettings ?? throw new ArgumentNullException(nameof(cronJobSettings));
}

public DateTime GetLastRun(ICronJob cronJob)
{
CronJobDataRow cronJobDataRow = GetOrCreateCronJobDataRow(cronJob);

return new DateTime(cronJobDataRow.LastRunTicks, DateTimeKind.Utc);
}

public void SetLastRun(ICronJob cronJob, DateTime lastRun)
{
CronJobDataRow cronJobDataRow = GetOrCreateCronJobDataRow(cronJob);
cronJobDataRow.LastRunTicks = lastRun.Ticks;
_cronJobSettings.Update(cronJobDataRow);
}

private CronJobDataRow GetOrCreateCronJobDataRow(ICronJob cronJob)
{
CronJobDataRow cronJobDataRow = _cronJobSettings.Select(cj => cj.JobId.Equals(cronJob.JobId) && cj.Name.Equals(cronJob.Name)).FirstOrDefault();

if (cronJobDataRow == null)
{
cronJobDataRow = new()
{
JobId = cronJob.JobId,
Name = cronJob.Name,
UpdatedTicks = DateTime.MinValue.Ticks
};

_cronJobSettings.Insert(cronJobDataRow);
}

return cronJobDataRow;
}
}
}
79 changes: 79 additions & 0 deletions DAL/PluginManager.DAL.TextFiles/Tables/CronJob/CronJobDataRow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* .Net Core Plugin Manager is distributed under the GNU General Public License version 3 and
* is also available under alternative licenses negotiated directly with Simon Carter.
* If you obtained Service Manager under the GPL, then the GPL applies to all loadable
* Service Manager modules used on your system as well. The GPL (version 3) is
* available at https://opensource.org/licenses/GPL-3.0
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* The Original Code was created by Simon Carter (s1cart3r@gmail.com)
*
* Copyright (c) 2024 Simon Carter. All Rights Reserved.
*
* Product: PluginManager.DAL.TextFiles
*
* File: CronJobDataRow.cs
*
* Purpose: Row definition for Table for cron jobs
*
* Date Name Reason
* 26/08/2024 Simon Carter Initially Created
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
using SimpleDB;

namespace PluginManager.DAL.TextFiles.Tables
{
[Table(Constants.TableNameCronJobs, CompressionType.None, CachingStrategy.SlidingMemory, WriteStrategy.Forced)]
internal sealed class CronJobDataRow : TableRowDefinition
{
private Guid _jobId;
private string _name;
private long _lastRunTicks;

public Guid JobId
{
get => _jobId;

set
{
if (_jobId == value)
return;

_jobId = value;
Update();
}
}

public string Name
{
get => _name;

set
{
if (_name == value)
return;

_name = value;
Update();
}
}

public long LastRunTicks
{
get => _lastRunTicks;

set
{
if (_lastRunTicks == value)
return;

_lastRunTicks = value;
Update();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Plugins\Cron.Plugin\Cron.Plugin.csproj" />
<ProjectReference Include="..\..\Plugins\Resources.Plugin\Resources.Plugin.csproj" />
<ProjectReference Include="..\..\SharedPluginFeatures\SharedPluginFeatures.csproj" />
<ProjectReference Include="..\..\NetCorePluginManager\AspNetCore.PluginManager.csproj" />
Expand Down
5 changes: 5 additions & 0 deletions Demo/NetCorePluginDemoWebsite/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* 22/09/2018 Simon Carter Initially Created
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
using System;
using System.Diagnostics.CodeAnalysis;

using AspNetCore.PluginManager.DemoWebsite.Classes;
Expand All @@ -36,6 +37,8 @@

using Shared.Classes;

using SharedPluginFeatures;

using rp = Resources.Plugin;

namespace AspNetCore.PluginManager.DemoWebsite
Expand All @@ -49,6 +52,7 @@ public static void Main(string[] args)
ThreadManager.MaximumPoolSize = 500;
ThreadManager.MaximumRunningThreads = 50;
ThreadManager.ThreadCpuChangeNotification = 0;
ThreadManager.ThreadHangTimeout = TimeSpan.FromMinutes(5);

// add plugins which need to be loaded first in a specific order
PluginManagerService.UsePlugin(typeof(ApiAuthorization.Plugin.PluginInitialisation));
Expand Down Expand Up @@ -93,6 +97,7 @@ public static void Main(string[] args)
PluginManagerService.UsePlugin(typeof(DynamicContent.Plugin.PluginInitialisation));
PluginManagerService.UsePlugin(typeof(rp.PluginInitialisation));
PluginManagerService.UsePlugin(typeof(SearchPlugin.PluginInitialisation));
PluginManagerService.UsePlugin(typeof(Cron.Plugin.PluginInitialisation));

CreateWebHostBuilder(args).Build().Run();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
9 changes: 5 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" Condition="'$(ImportByWildcardBeforeMicrosoftCommonTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\$(MSBuildThisFile)\ImportBefore')"/>

<PropertyGroup>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
<NoWarn>1701;1702;8032;8981;S125;S6967;S6964;S6670;S6934;S3267;IDE0290</NoWarn>
<RunAnalyzers>true</RunAnalyzers>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<NoWarn>1701;1702;8032;8981;S125;S6967;S6964;S6670;S6934;S3267;S3431;IDE0290</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>Shared.Key.pfx</AssemblyOriginatorKeyFile>
Expand Down Expand Up @@ -35,8 +36,8 @@
</PropertyGroup>

<PropertyGroup>
<SharedVer>3.15.0</SharedVer>
<SharedWinVer>1.5.0</SharedWinVer>
<SharedVer>3.16.0</SharedVer>
<SharedWinVer>1.6.0</SharedWinVer>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
1 change: 1 addition & 0 deletions Docs/Custom/Cron.Plugin/SortOrder.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5000
3 changes: 2 additions & 1 deletion Docs/Settings/Files.dat
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ ImageManager.Plugin.xml
DynamicContent.Plugin.xml
ApiAuthorization.Plugin.xml
Resources.Plugin.xml
SimpleDb.xml
SimpleDb.xml
CronJob.Plugin.xml
Loading

0 comments on commit 6a08e0a

Please sign in to comment.