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

Add support to scheduler message #3487

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

lillo42
Copy link
Contributor

@lillo42 lillo42 commented Jan 20, 2025

  • 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

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🔥

View detailed results in CodeScene

@@ -37,6 +37,8 @@ THE SOFTWARE. */
using Paramore.Brighter.FeatureSwitch;
using Paramore.Brighter.Logging;
using Paramore.Brighter.Observability;
using Paramore.Brighter.Scheduler.Events;

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

Suppress

@@ -37,6 +37,8 @@ THE SOFTWARE. */
using Paramore.Brighter.FeatureSwitch;
using Paramore.Brighter.Logging;
using Paramore.Brighter.Observability;
using Paramore.Brighter.Scheduler.Events;

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

Comment on lines +274 to +296
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);
}
}

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

Comment on lines +299 to +321
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);
}
}

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

Comment on lines +132 to +133
InstrumentationOptions instrumentationOptions = InstrumentationOptions.All,
IAmAMessageSchedulerFactory? messageSchedulerFactory = null)

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

Comment on lines +183 to +185
InstrumentationOptions instrumentationOptions = InstrumentationOptions.All,
IAmAMessageSchedulerFactory? messageSchedulerFactory = null)
: this(subscriberRegistry, handlerFactory, requestContextFactory, policyRegistry, featureSwitchRegistry, inboxConfiguration, messageSchedulerFactory: messageSchedulerFactory)

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

Comment on lines +95 to +113
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);
}
}

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

Suppress

@@ -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>();

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

Suppress

Comment on lines +49 to +75
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();
}
}

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

Suppress

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🔥

View detailed results in CodeScene

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant