-
Notifications
You must be signed in to change notification settings - Fork 259
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
Add support to scheduler message #3487
base: master
Are you sure you want to change the base?
Conversation
lillo42
commented
Jan 20, 2025
•
edited
Loading
edited
- Remove unnecessary code
- Fixes build
- Add Unit test
- Finish implementation
- Add Sample
- Implement support to HangFire
- Implement support to Quartz
- Implement support to AWS Scheduler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Code Health Quality Gates: FAILED
Change in average Code Health of affected files: -0.02 (8.17 -> 8.15)
-
Declining Code Health: 4 findings(s) 🚩
-
Affected Hotspots: 2 files(s) 🔥
@@ -37,6 +37,8 @@ THE SOFTWARE. */ | |||
using Paramore.Brighter.FeatureSwitch; | |||
using Paramore.Brighter.Logging; | |||
using Paramore.Brighter.Observability; | |||
using Paramore.Brighter.Scheduler.Events; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Getting worse: Code Duplication
introduced similar code in: SchedulerAsync,SchedulerAsync,SchedulerPost,SchedulerPost
@@ -37,6 +37,8 @@ THE SOFTWARE. */ | |||
using Paramore.Brighter.FeatureSwitch; | |||
using Paramore.Brighter.Logging; | |||
using Paramore.Brighter.Observability; | |||
using Paramore.Brighter.Scheduler.Events; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ Getting worse: Missing Arguments Abstractions
The average number of function arguments increases from 4.12 to 4.17, threshold = 4.00
public async Task SchedulerAsync<TRequest>(TimeSpan delay, | ||
TRequest request, | ||
RequestContext? requestContext = null, | ||
bool continueOnCapturedContext = true, | ||
CancellationToken cancellationToken = default) | ||
where TRequest : class, IRequest | ||
{ | ||
if (_messageSchedulerFactory == null) | ||
{ | ||
throw new InvalidOperationException("No message scheduler factory set."); | ||
} | ||
|
||
s_logger.LogInformation("Scheduling request: {RequestType} {Id}", request.GetType(), request.Id); | ||
var scheduler = _messageSchedulerFactory.Create(this); | ||
if (scheduler is IAmAMessageSchedulerAsync asyncScheduler) | ||
{ | ||
await asyncScheduler.ScheduleAsync(delay, SchedulerFireType.Post, request, cancellationToken); | ||
} | ||
else if (scheduler is IAmAMessageSchedulerSync sync) | ||
{ | ||
sync.Schedule(delay, SchedulerFireType.Post, request); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ New issue: Excess Number of Function Arguments
SchedulerAsync has 5 arguments, threshold = 4
public async Task SchedulerAsync<TRequest>(DateTimeOffset at, | ||
TRequest request, | ||
RequestContext? requestContext = null, | ||
bool continueOnCapturedContext = true, | ||
CancellationToken cancellationToken = default) | ||
where TRequest : class, IRequest | ||
{ | ||
if (_messageSchedulerFactory == null) | ||
{ | ||
throw new InvalidOperationException("No message scheduler factory set."); | ||
} | ||
|
||
s_logger.LogInformation("Scheduling request: {RequestType} {Id}", request.GetType(), request.Id); | ||
var scheduler = _messageSchedulerFactory.Create(this); | ||
if (scheduler is IAmAMessageSchedulerAsync asyncScheduler) | ||
{ | ||
await asyncScheduler.ScheduleAsync(at, SchedulerFireType.Post, request, cancellationToken); | ||
} | ||
else if (scheduler is IAmAMessageSchedulerSync sync) | ||
{ | ||
sync.Schedule(at, SchedulerFireType.Post, request); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ New issue: Excess Number of Function Arguments
SchedulerAsync has 5 arguments, threshold = 4
InstrumentationOptions instrumentationOptions = InstrumentationOptions.All, | ||
IAmAMessageSchedulerFactory? messageSchedulerFactory = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ Getting worse: Constructor Over-Injection
CommandProcessor increases from 8 to 9 arguments, threshold = 5
InstrumentationOptions instrumentationOptions = InstrumentationOptions.All, | ||
IAmAMessageSchedulerFactory? messageSchedulerFactory = null) | ||
: this(subscriberRegistry, handlerFactory, requestContextFactory, policyRegistry, featureSwitchRegistry, inboxConfiguration, messageSchedulerFactory: messageSchedulerFactory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ Getting worse: Constructor Over-Injection
CommandProcessor increases from 11 to 12 arguments, threshold = 5
public void Add(SchedulerMessage message) | ||
{ | ||
lock (_lock) | ||
{ | ||
var node = _messages.First; | ||
while (node != null) | ||
{ | ||
if (node.Value.At > message.At) | ||
{ | ||
_messages.AddBefore(node, message); | ||
return; | ||
} | ||
|
||
node = node.Next; | ||
} | ||
|
||
_messages.AddLast(message); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ New issue: Code Duplication
The module contains 2 functions with similar structure: Add,Delete
@@ -139,6 +141,7 @@ public Dispatcher Build(string hostName) | |||
var subscriberRegistry = new SubscriberRegistry(); | |||
subscriberRegistry.Register<ConfigurationCommand, ConfigurationCommandHandler>(); | |||
subscriberRegistry.Register<HeartbeatRequest, HeartbeatRequestCommandHandler>(); | |||
subscriberRegistry.RegisterAsync<SchedulerMessageFired, SchedulerMessageFiredHandlerAsync>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Getting worse: Large Method
Build increases from 73 to 74 lines of code, threshold = 70
private static ValueTask ExecuteAsync<TRequest>(IAmACommandProcessor commandProcessor, | ||
string data, | ||
bool async, | ||
SchedulerFireType fireType, | ||
CancellationToken cancellationToken) | ||
where TRequest : class, IRequest | ||
{ | ||
var request = JsonSerializer.Deserialize<TRequest>(data, JsonSerialisationOptions.Options)!; | ||
switch (fireType) | ||
{ | ||
case SchedulerFireType.Send when async: | ||
return new ValueTask(commandProcessor.SendAsync(request, cancellationToken: cancellationToken)); | ||
case SchedulerFireType.Send: | ||
commandProcessor.Send(request); | ||
return new ValueTask(); | ||
case SchedulerFireType.Publish when async: | ||
return new ValueTask(commandProcessor.PublishAsync(request, cancellationToken: cancellationToken)); | ||
case SchedulerFireType.Publish: | ||
commandProcessor.Publish(request); | ||
return new ValueTask(); | ||
case SchedulerFireType.Post when async: | ||
return new ValueTask(commandProcessor.PostAsync(request, cancellationToken: cancellationToken)); | ||
default: | ||
commandProcessor.Post(request); | ||
return new ValueTask(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ New issue: Excess Number of Function Arguments
ExecuteAsync has 5 arguments, threshold = 4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Code Health Quality Gates: FAILED
Change in average Code Health of affected files: -0.02 (8.17 -> 8.15)
-
Declining Code Health: 4 findings(s) 🚩
-
Affected Hotspots: 2 files(s) 🔥