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

Teach IInstantJobRegistry to accept named jobs #215

Merged
merged 4 commits into from
Feb 27, 2025
Merged

Teach IInstantJobRegistry to accept named jobs #215

merged 4 commits into from
Feb 27, 2025

Conversation

nulltoken
Copy link
Collaborator

@nulltoken nulltoken commented Feb 26, 2025

Pull request description

Follow up to #213
Provides a design escape hatch trough new overloads in IInstantJobRegistry.

PR meta checklist

  • Pull request is targeted at main branch for code
  • Pull request is linked to all related issues, if any.

Code PR specific checklist

  • My code follows the code style of this project and AspNetCore coding guidelines.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • I have updated the appropriate sub section in the CHANGELOG.md.
  • I have added, updated or removed tests to according to my changes.
    • All tests passed.

Copy link

codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
...NCronJob/Configuration/Builder/JobOptionBuilder.cs 100.00% <100.00%> (ø)
...NCronJob/Configuration/Builder/ParameterBuilder.cs 100.00% <ø> (ø)
...nJob/Configuration/Builder/ParameterOnlyBuilder.cs 100.00% <100.00%> (ø)
src/NCronJob/Configuration/DynamicJobFactory.cs 94.44% <100.00%> (+8.33%) ⬆️
src/NCronJob/Registry/IInstantJobRegistry.cs 95.29% <100.00%> (+1.96%) ⬆️

/// <param name="jobName">The job name associated with this job.</param>
/// <returns>Returns a <see cref="ParameterBuilder"/> that allows further configuration.</returns>
/// <remarks>The job name should be unique over all job instances.</remarks>
public ParameterBuilder WithName(string jobName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm now that isn't the best choice. The user can do the following:

j => j.WithName("Foo").WithName("Bar");

As the ParameterBuilder also has a ParameterBuilder.

To remove the ambiguity, we could have a WithParameter property that directly returns the ParameterBuilder:

j => j.WithParameter.WithName("Foo");

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On it.

Copy link
Collaborator Author

@nulltoken nulltoken Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came up with a different proposal. Thoughts?

  • Prevents the WithName().WithName() issue
  • Allows the WithParameter().WithParameter() usage (for current fluent branches)
  • Prevents the WithParameter().WithParameter() issue (for new fluent branch)
  • Backward compatible (from an API standpoint)

May need to be cleaned up in v5 to come up with something tighter.

Copy link
Member

@linkdotnet linkdotnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start - but the API isn't quite there yet.

If the shape is what we want, we need some documentation for the feature and why it exists.

@nulltoken
Copy link
Collaborator Author

Good start - but the API isn't quite there yet.

If the shape is what we want, we need some documentation for the feature and why it exists.

Doco and changelog are on my todo list once you like the API shape enough.

@nulltoken nulltoken force-pushed the ntk/name branch 2 times, most recently from f48b76f to b3459b8 Compare February 26, 2025 18:03
@linkdotnet
Copy link
Member

Good start - but the API isn't quite there yet.
If the shape is what we want, we need some documentation for the feature and why it exists.

Doco and changelog are on my todo list once you like the API shape enough.

We are 98% there. If we drop the abstract class, I like the API 100% ;)

/// <summary>
/// Chains another option to the job.
/// </summary>
#pragma warning disable CA1716 // Identifiers should not match keywords
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, put this into the .editorconfig

It is not valid for the whole project, not just this place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nulltoken nulltoken force-pushed the ntk/name branch 4 times, most recently from fe56469 to 1be45cf Compare February 26, 2025 21:25
@@ -60,7 +60,7 @@ public Task RunAsync(IJobExecutionContext context, CancellationToken token)
var arguments = new object[parameters.Length];
for (var i = 0; i < parameters.Length; i++)
{
if (parameters[i].ParameterType == typeof(JobExecutionContext))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As JobExecutionContext isn't a public type, dynamic jobs can't even declare it as parameter.
Switching this to IJobExecutionContext aligns with the what the doco advertizes

@nulltoken
Copy link
Collaborator Author

Good start - but the API isn't quite there yet.
If the shape is what we want, we need some documentation for the feature and why it exists.

Doco and changelog are on my todo list once you like the API shape enough.

@linkdotnet Done

@nulltoken nulltoken requested a review from linkdotnet February 27, 2025 15:45
@nulltoken nulltoken merged commit 3a50868 into main Feb 27, 2025
5 checks passed
@nulltoken nulltoken deleted the ntk/name branch February 27, 2025 19:37
@linkdotnet
Copy link
Member

@nulltoken Thanks again - for everything!

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.

2 participants