Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

177/circuit breaker #419

Merged
merged 9 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generic jobs/InfluxDBCheck/InfluxDBCheck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="InfluxDB.Client" Version="4.17.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.12" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion generic jobs/RabbitMQCheck/RabbitMQCheck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="RestSharp" Version="112.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion generic jobs/RedisCheck/RedisCheck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.12" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion generic jobs/RedisOperations/RedisOperations.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="Cronos" Version="0.8.4" />
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
<PackageReference Include="StackExchange.Redis" Version="2.8.12" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion generic jobs/SqlQueryCheck/SqlQueryCheck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion generic jobs/SqlTableRetention/SqlTableRetention.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion nuget packages/AigSmsHook/AigSmsHook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="RestSharp" Version="112.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion nuget packages/ClientLibraryTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
var provider = services.BuildServiceProvider();
var client = provider.GetRequiredService<IPlanarClient>();

var odata = await client.History.ODataAsync(new ODataFilter { Filter = "triggerid eq 'manual'", Select = "xx,jobid" });
var odata = await client.History.ODataAsync(new ODataFilter { Filter = "triggerid eq 'manual'", Select = "jobname,jobid" });
Console.WriteLine(odata);
var details = await client.Job.GetAsync("Demo.HelloWorld");
Console.WriteLine(details.Active);
details = await client.Job.GetAsync(jobid1);
Console.WriteLine(details.Active);
details = await client.Job.GetAsync("Monitoring.HealthCheck");
Console.WriteLine(details.Active);
details = await client.Job.GetAsync("CircuitBreaker.CircuitBreakerTester");
Console.WriteLine(details.Active);

var group = await client.Group.GetAsync("Admins");
Console.WriteLine(group.Name);
Expand Down
16 changes: 16 additions & 0 deletions nuget packages/Planar.Client/Entities/JobCircuitBreaker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Planar.Client.Entities
{
public class JobCircuitBreaker
{
public int FailureThreshold { get; set; }
public int SuccessThreshold { get; set; }
public TimeSpan? PauseSpan { get; set; }
public int FailCounter { get; set; }
public int SuccessCounter { get; set; }
public DateTime? WillBeResetAt { get; set; }
public DateTime? ActivatedAt { get; set; }
public bool Activated => ActivatedAt.HasValue;
}
}
9 changes: 1 addition & 8 deletions nuget packages/Planar.Client/Entities/JobDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,14 @@ namespace Planar.Client.Entities
public class JobDetails : JobBasicDetails
{
public string? Author { get; set; }

public int? LogRetentionDays { get; set; }

public bool Durable { get; set; }

public bool RequestsRecovery { get; set; }

public bool Concurrent { get; set; }

public string Properties { get; set; } = string.Empty;

public Dictionary<string, string?> DataMap { get; set; } = new Dictionary<string, string?>();

public List<SimpleTriggerDetails> SimpleTriggers { get; set; } = new List<SimpleTriggerDetails>();

public List<CronTriggerDetails> CronTriggers { get; set; } = new List<CronTriggerDetails>();
public JobCircuitBreaker? CircuitBreaker { get; set; }
}
}
4 changes: 2 additions & 2 deletions nuget packages/Planar.Client/Planar.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="111.4.1" />
<PackageReference Include="RestSharp" Version="112.0.0" />
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="112.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion nuget packages/Planar.Job.Test/Planar.Job.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="YamlDotNet" Version="16.0.0" />
<PackageReference Include="YamlDotNet" Version="16.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 6 additions & 2 deletions nuget packages/Planar.Job/BaseJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,19 @@ internal async Task Execute(string json)
var task = ExecuteJob(_context);
await Task.WhenAll(task);
_timer?.Stop();
var mapperBack = new JobBackMapper(_logger, _baseJobFactory);
mapperBack.MapJobInstancePropertiesBack(_context, this);
}
catch (Exception ex)
{
HandleException(ex);
}
finally
{
SafeHandle(() =>
{
var mapperBack = new JobBackMapper(_logger, _baseJobFactory);
mapperBack.MapJobInstancePropertiesBack(_context, this);
});

SafeHandle(() => _timer?.Dispose());
SafeHandle(() => MqttClient.Connected -= MqttClient_Connected);
await SafeHandleAsync(() => MqttClient.StopAsync());
Expand Down
2 changes: 1 addition & 1 deletion nuget packages/Planar.Job/Planar.Job.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="MQTTnet.Extensions.ManagedClient" Version="4.3.6.1152" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
<PackageReference Include="YamlDotNet" Version="16.0.0" />
<PackageReference Include="YamlDotNet" Version="16.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions nuget packages/UnitTest/UnitTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<NoWarn>1701;1702;NU1803</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/DbUp/dbup-sqlserver/dbup-sqlserver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.1" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Hooks/Planar.Hooks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<PackageReference Include="CloudNative.CloudEvents.SystemTextJson" Version="2.8.0" />
<PackageReference Include="MailKit" Version="4.7.1.1" />
<PackageReference Include="Planar.Hook" Version="1.7.6" />
<PackageReference Include="StackExchange.Redis" Version="2.8.0" />
<PackageReference Include="Twilio" Version="7.2.2" />
<PackageReference Include="StackExchange.Redis" Version="2.8.12" />
<PackageReference Include="Twilio" Version="7.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/CommonJob/BaseCommonJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected void SafeScan(MonitorEvents @event, IJobExecutionContext context)
catch (Exception ex)
{
var source = nameof(SafeScan);
_logger.LogCritical(ex, "Error handle {Source}: {Message} ", source, ex.Message);
_logger.LogCritical(ex, "Error handle {Source}: {Message}", source, ex.Message);
}
}

Expand Down
92 changes: 45 additions & 47 deletions src/Jobs/CommonJob/JobExecutionMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,73 @@
using Planar;
using IJobExecutionContext = Quartz.IJobExecutionContext;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IJobExecutionContext = Quartz.IJobExecutionContext;

namespace CommonJob;

namespace CommonJob
public class JobExecutionMetadata
{
public class JobExecutionMetadata
{
public StringBuilder Log { get; set; } = new StringBuilder();
public StringBuilder Log { get; set; } = new StringBuilder();

public List<ExceptionDto> Exceptions { get; set; } = new List<ExceptionDto>();
public List<ExceptionDto> Exceptions { get; set; } = new List<ExceptionDto>();

public int? EffectedRows { get; set; }
public int? EffectedRows { get; set; }

public byte Progress { get; set; }
public byte Progress { get; set; }

public bool HasWarnings { get; set; }
public bool HasWarnings { get; set; }

private static readonly object Locker = new();
private static readonly object Locker = new();

public string GetLog()
public string GetLog()
{
return Log.ToString();
}

public string GetExceptionsText()
{
var exceptions = Exceptions;
if (exceptions == null || exceptions.Count == 0)
{
return Log.ToString();
return string.Empty;
}

public string GetExceptionsText()
if (exceptions.Count == 1)
{
var exceptions = Exceptions;
if (exceptions == null || exceptions.Count == 0)
{
return string.Empty;
}

if (exceptions.Count == 1)
{
return exceptions[0].ExceptionText ?? string.Empty;
}
return exceptions[0].ExceptionText ?? string.Empty;
}

var seperator = string.Empty.PadLeft(80, '-');
var sb = new StringBuilder();
sb.AppendLine($"There is {exceptions.Count} aggregate exception");
exceptions.ForEach(e => sb.AppendLine($" - {e.Message}"));
var seperator = string.Empty.PadLeft(80, '-');
var sb = new StringBuilder();
sb.AppendLine($"There is {exceptions.Count} aggregate exception");
exceptions.ForEach(e => sb.AppendLine($" - {e.Message}"));
sb.AppendLine(seperator);
exceptions.ForEach(e =>
{
sb.AppendLine(e.ExceptionText);
sb.AppendLine(seperator);
exceptions.ForEach(e =>
{
sb.AppendLine(e.ExceptionText);
sb.AppendLine(seperator);
});
});

return sb.ToString();
}
return sb.ToString();
}

public Exception? UnhandleException { get; set; }
public Exception? UnhandleException { get; set; }

public bool IsRunningFail => !IsRunningSuccess;
public bool IsRunningSuccess => UnhandleException == null;
public bool IsRunningFail => !IsRunningSuccess;
public bool IsRunningSuccess => UnhandleException == null;

public static JobExecutionMetadata GetInstance(IJobExecutionContext context)
public static JobExecutionMetadata GetInstance(IJobExecutionContext context)
{
lock (Locker)
{
lock (Locker)
if (context.Result is not JobExecutionMetadata result)
{
if (context.Result is not JobExecutionMetadata result)
{
result = new JobExecutionMetadata();
context.Result = result;
}

return result;
result = new JobExecutionMetadata();
context.Result = result;
}

return result;
}
}
}
6 changes: 6 additions & 0 deletions src/Jobs/PlanarJob/JobFile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ properties: # Job Properties
username: null # local or network username (any OS) [up to 100 characters]
password: null # The active directory password (only on windows OS) [up to 100 characters]

circuit breaker:
enabled: true # Boolean [true/false]. Enable/Disable the circuit breaker
failure threshold: 5 # The number of failures that will trip the circuit breaker [2 to 100]
success threshold: 1 # The number of successes that will reset the circuit breaker [1 to 100]
pause span: 01:00:00 # The time span which the circuit breaker will pause the job execution. set null value for permanent pause. minimum value is 5 minutes

simple triggers: # List of simple triggers
- name: every-minute-trigger # Name of trigger [mandatory, only alphanumeric, dashes & underscore, 5 to 50 characters]
start: 2021-09-19 00:00:00 # Start date
Expand Down
6 changes: 6 additions & 0 deletions src/Jobs/ProcessJob/JobFile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ properties: # Job Properties
success output regex: "[Ss]uccess" # Regular expression to define success run
fail output regex: "[Ee]rror" # Regular expression to define fail run

circuit breaker:
enabled: true # Boolean [true/false]. Enable/Disable the circuit breaker
failure threshold: 5 # The number of failures that will trip the circuit breaker [2 to 100]
success threshold: 1 # The number of successes that will reset the circuit breaker [1 to 100]
pause span: 01:00:00 # The time span which the circuit breaker will pause the job execution. set null value for permanent pause. minimum value is 5 minutes

simple triggers: # List of simple triggers
- name: every-minute-trigger # Name of trigger [mandatory, only alphanumeric, dashes & underscore, 5 to 50 characters]
start: 2021-09-19 00:00:00 # Start date
Expand Down
6 changes: 6 additions & 0 deletions src/Jobs/RestJob/JobFile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ properties: # Job Properties
header2: some value y # key --> [mandatory, up to 100 characters]
header3: some value z # value --> [up to 1000 characters]

circuit breaker:
enabled: true # Boolean [true/false]. Enable/Disable the circuit breaker
failure threshold: 5 # The number of failures that will trip the circuit breaker [2 to 100]
success threshold: 1 # The number of successes that will reset the circuit breaker [1 to 100]
pause span: 01:00:00 # The time span which the circuit breaker will pause the job execution. set null value for permanent pause. minimum value is 5 minutes

simple triggers: # List of simple triggers
- name: every-minute-trigger # Name of trigger [mandatory, only alphanumeric, dashes & underscore, 5 to 50 characters]
start: 2021-09-19 00:00:00 # Start date
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/RestJob/RestJob.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="RestSharp" Version="111.4.1" />
<PackageReference Include="RestSharp" Version="112.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/Jobs/SqlJob/JobFile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ properties: # Job Properties
connection name: <name>
timeout: 00:00:30

circuit breaker:
enabled: true # Boolean [true/false]. Enable/Disable the circuit breaker
failure threshold: 5 # The number of failures that will trip the circuit breaker [2 to 100]
success threshold: 1 # The number of successes that will reset the circuit breaker [1 to 100]
pause span: 01:00:00 # The time span which the circuit breaker will pause the job execution. set null value for permanent pause. minimum value is 5 minutes

simple triggers: # List of simple triggers
- name: every-minute-trigger # Name of trigger [mandatory, only alphanumeric, dashes & underscore, 5 to 50 characters]
start: 2021-09-19 00:00:00 # Start date
Expand Down
Loading
Loading