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

How to schedule a one-off event at run-time? #314

Open
jackfox10 opened this issue Dec 1, 2021 · 2 comments
Open

How to schedule a one-off event at run-time? #314

jackfox10 opened this issue Dec 1, 2021 · 2 comments

Comments

@jackfox10
Copy link

Ok I know this is against the idea of using a scheduler but what if I have a use case where I want to schedule a job every x minutes but also when an event happens?

An example would be refreshing data every five minutes but also refreshing data when a user clicks a button for example.

As far as I know there this would not work:

registry.Schedule<MyJob>().ToRunEvery(5).Minutes();
onEventFired(() => registry.Schedule<MyJob>().ToRunNow());

But is there a way to get the scheduler to run the job as a one off?

I could of course just run the code from within onEventFired without the scheduler but I would be worried about thread safety in this case and would prefer to use the scheduler.

Thanks!

@ghost
Copy link

ghost commented Dec 2, 2021

Inside the event handler just call JobManager.AddJob directly without having to schedule a Registry class. When you schedule a Registry you have to call JobManager.Initialize.

@mrgfisher
Copy link

Another option @jackfox10 ...

I've use the scheduler as thin as possible in the job defnition. Effectively all it does it fire of a command using the mediatr library (https://github.com/jbogard/MediatR) with the implementation in some other assembly. Then I've referenced the same assembly from whereever I can respond the user event and that too fires of a command. The handler then 'does its thing' caring not if its scheduled or user drive. i.e it's more about seperating the concerns into three - schedule a command, respond to user event with command, act on command.

Hope that makes some sense 😊

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

No branches or pull requests

2 participants