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

feat: Support Startup Jobs #43 #70

Merged
merged 9 commits into from
May 25, 2024

Conversation

falvarez1
Copy link
Member

@falvarez1 falvarez1 commented May 22, 2024

Description

This PR introduces support for "startup jobs" and "one-time jobs" in the NCronJob library. These enhancements allow for tasks that need to be executed once during the application startup phase or at a specific moment, respectively. Key changes include:

  • Startup Jobs: Execute once at the beginning of the application lifecycle, suitable for tasks like data migrations or initial data setups.
  • Sample Project: Provide sample project that demonstrates the new feature.
  • Improved API: Limit API methods to better guide the developer during setup.

Related Issue

Closes #43

Checklist

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

- restructured the NCronJobOptionsBuilder and JobOptionsBuilder so that the builder pattern delays the build() so we can finalize setting the options
@falvarez1 falvarez1 changed the title support One Time Jobs and Startup Jobs #43 feat: Support One Time Jobs and Startup Jobs #43 May 23, 2024
@falvarez1 falvarez1 force-pushed the run-once-startup-jobs branch from 4aefdc4 to c18139e Compare May 23, 2024 06:04
@falvarez1 falvarez1 force-pushed the run-once-startup-jobs branch from c18139e to 2022c70 Compare May 23, 2024 06:05
@falvarez1 falvarez1 changed the title feat: Support One Time Jobs and Startup Jobs #43 feat: Support Startup Jobs #43 May 23, 2024
@falvarez1 falvarez1 marked this pull request as ready for review May 23, 2024 18:59
@@ -15,6 +15,10 @@ internal sealed record JobDefinition(

public CancellationToken CancellationToken { get; set; }

public bool IsOneTimeJob=> (CronExpression is null && RunAt != null) || IsStartupJob;
public DateTimeOffset? RunAt { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Is this still needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not particularly for this PR, but I added the same to another branch I'm working on for a bug fix related to instant jobs, so I just left it. I'll can remove it to not have to deal with merge issues.

@@ -0,0 +1,33 @@
namespace NCronJob;
internal class StartupJobManager(JobRegistry jobRegistry)
Copy link
Member

Choose a reason for hiding this comment

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

For reasons of consistency, I would refrain from using primary constructors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, we should add an analyzer rule too.

Copy link
Member

Choose a reason for hiding this comment

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

Well technically I don't think there is one. I marked IDE0290 as none.

Not that I am absolutely against it, but I do think we need some shared guidelines and "enforce" them to some extent.

Copy link
Member

Choose a reason for hiding this comment

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

So I am absolutely open to challenge the current coding standard/guidelines, especially if you feel that they are in your way and hinder productivity.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like the compactness of primary constructors. The only time they seem to get in the way is when using the source generated LoggerMessage.

@falvarez1 falvarez1 force-pushed the run-once-startup-jobs branch from ccfcdad to 49ca27e Compare May 25, 2024 00:34
@falvarez1 falvarez1 merged commit e29b774 into NCronJob-Dev:main May 25, 2024
3 checks passed
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.

Allow "one-time" jobs
2 participants