jamesmh / coravel

Near-zero config .NET library that makes advanced application features like Task Scheduling, Caching, Queuing, Event Broadcasting, and more a breeze!
https://docs.coravel.net/Installation/
MIT License
3.65k stars 242 forks source link

Support for cancellable invocables #136

Closed Blinke closed 4 years ago

Blinke commented 4 years ago

Thank you for your contribution! Before submitting this PR, please make sure:

Other Notes:

Coravel is created with a specific vision and philosophy:

To that effect, don't feel bad when many changes are asked of your PR 😉


Implementation for #133

As far as I can tell, the cancellation token passed to IHostedService.StartAsync is only used to cancel the startup process and does not get triggered on shutdown. Instead I created one in the scheduler and trigger the cancellation manually on shutdown before waiting for all the tasks to finish.

I haven't tackled updating the documentation yet. Let me know if you'd like me to or if you'll write it up yourself.

jamesmh commented 4 years ago

Awesome work! Love it. I'll add some docs after the merge.

Blinke commented 4 years ago

Great! I've used Coravel for multiple projects at work so it feels good to be able to make some contributions even if they are pretty small 😊

jamesmh commented 4 years ago

Nice! So far I think you've contributed the most features other than myself 😄

I'd love to hear about what kind of projects you're using Coravel for too 👍

Blinke commented 4 years ago

We're using it for some pretty simple stuff right now, just running scripts on different intervals to verify data from an unreliable legacy system and send notifications when anomalies are found. We have a similar service running as a Kubernetes cronjob that we will also move to Coravel soon.

Then we have a pretty complex data scraping/caching service that I would like to move from Hangfire to Coravel since we don't have any need for persistence or distributed schedulers 🙂

jamesmh commented 4 years ago

That's some pretty cool stuff. Are there any specific benefits you've found between Hangfire vs. Coravel? I know Coravel is (probably) easier to get started with, seems to have a simpler API and has full async. Any other considerations that make you want to move over?

Have you run into any issues or blockers for perhaps more complex uses? I've got some ideas to make Coravel easier/more compatible with microservices and more complex project configurations. Wondering if there are any other things that real-usage has revealed (to you)?

Blinke commented 4 years ago

The simplicity is the main reason for wanting to move over at this point. Hangfire has a lot bells and whistles that are really nice if you actually need them. Turns out that we don't, for the most part. It works just fine but it's a bit overkill for our application and adds unnecessary complexity.

We also kept encountering issues the first couple of months of using Hangfire that were not always straightforward to troubleshoot. I'm sure a lot of it was user error and just not knowing how to do things properly but it was still a bit of a roadblock for us. Setting up Coravel, on the other hand, is really hard to get wrong.

Something I do miss in Coravel that Hangfire supports is being able to limit how many queued jobs can execute at once. Having named queues with different configurations is also a plus.

Our scrape service runs some checks every 15 minutes and then queues up one or more jobs if there is new data available. These jobs can take anywhere between 5 and 20 minutes each and most of the time is spent making HTTP requests and waiting for responses. For a more steady throughput and to not overload the API we consume, the queue only processes a few jobs at a time instead of all of them at once.

schmitch commented 4 years ago

btw. my company basically can support all use cases with coravel that we used in hangfire with this PR. so really thanks @Blinke. the only thing is the dashboard that is only usable in coravel pro and schedules (with parameters) that are stored inside the database (but we can't upgrade to 1.7.x since something is broken in Hangfire), so our plan is to dismiss database scheduling (since it was just a goody) and stick with coravel.

edit: oh and limiting how many queued jobs can execute at once is also one downside that we encountered, but not a big deal since we can easily disable queuing up new tasks, if a task is still running. (i.e. we only allow 1 queued task per invocable)

jamesmh commented 4 years ago

Awesome 👍 That's some helpful feedback.

@Blinke - you bring up some areas that others have brought up in other issues:

Blinke commented 4 years ago

@schmitch - Nice, I'm glad to hear that!

@jamesmh - Great to hear the feedback was useful 🙂 I've been having a really good time working on this so project so far, hopefully I can continue to contribute on the new issues.