Scheduling Background Tasks In .NET With Quartz

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ธ.ค. 2024

ความคิดเห็น • 165

  • @MilanJovanovicTech
    @MilanJovanovicTech  ปีที่แล้ว +5

    Get the source code for this video for FREE → the-dotnet-weekly.ck.page/quartz
    Want to master Clean Architecture? Go here: bit.ly/3PupkOJ
    Want to unlock Modular Monoliths? Go here: bit.ly/3SXlzSt

    • @kazepis
      @kazepis ปีที่แล้ว

      I was really hoping to see how you move the configuration to an external xml or json file. Maybe something for a “short” video? 😊

  • @AS-zj4jv
    @AS-zj4jv ปีที่แล้ว +12

    Dang Milan bro, you've got an answer for every .NET question I can possibly ask. Please don't ever stop making these videos.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +2

      Really glad to hear that! 😁 And I'm glad this video was valuable

  • @ManuelRaso-v4k
    @ManuelRaso-v4k ปีที่แล้ว +4

    No matter how varied what I am looking for may be, there always be a Milan's video which explain it in the best way

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      Hundreds of topics left to cover, but I'm glad some questions are being answered 😁

    • @ASIMKHAN-ig9eo
      @ASIMKHAN-ig9eo 11 หลายเดือนก่อน +1

      Exactly, and when i am in need to implement something in my project, milan video just pop up at my notifications

  • @cryptoeric24
    @cryptoeric24 ปีที่แล้ว +8

    Totally serious!!! You need to do a clean architecture bootcamp and spread the news, Mr. Clean Architecture Evangelist!!!

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +6

      My Clean Architecture course is coming out in the next 7-10 days, if all goes well. So that should be a nice start 😁😁

    • @techie607
      @techie607 ปีที่แล้ว

      Waiting

    • @stephanengaleu576
      @stephanengaleu576 ปีที่แล้ว

      ​@@MilanJovanovicTechso we are waiting for TH-cam notification 😊

    • @destinyhans8519
      @destinyhans8519 ปีที่แล้ว

      Can’t wait for the course 🎉

  • @cedricv-p9z
    @cedricv-p9z ปีที่แล้ว +12

    I really liked this video, but I had hoped to see an example of a request that starts a long running background process
    It would go something like this:
    1. http request is received
    2. long running task is initiated based on given request parameters
    3. if initiated correctly, http response is sent
    4. request sender will get long running task update by webhook
    All of this is probably too long for a single video, so maybe you can split it up between points 1,2,3 and 4
    Hope you like this idea!

  • @canyoldas2855
    @canyoldas2855 9 หลายเดือนก่อน +1

    You've made me a .NET beast. Thank you.

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 หลายเดือนก่อน +1

      Hah, that's awesome! Glad to hear :)

  • @thescarletcars
    @thescarletcars 10 หลายเดือนก่อน +1

    Thanks so much! this was very helpful!! Just about to write my first background job application with quartz

  • @CodeAlongWithMe
    @CodeAlongWithMe ปีที่แล้ว +1

    Excellent explanation, we need more videos like this one for understanding background tasks. Keep up the great work!

  • @MustakimTriveni
    @MustakimTriveni ปีที่แล้ว +1

    Thanks brother for sharing scheduler knowledge. it help me a lot.

  • @kodindoyannick5328
    @kodindoyannick5328 10 หลายเดือนก่อน +1

    Exciting content! Many thanks to you

  • @nove1398
    @nove1398 ปีที่แล้ว +1

    Nice share! I was looking into a solution for a problem lately and this was one of my options. I prefer a simple interface surface to work with.

  • @ayalamac
    @ayalamac ปีที่แล้ว +2

    I imagine an API that post the construction of new routine in quartz with the given params about how often it will work and the destination or subjects involved. Every time the post method in the controller is called, another instance is launched doing a different thing. This will be for configuring multiple data refreshing jobs for several powerbi dashboards, using their rest api

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      I see... You can configure a job instance, and trigger the schedule manually. Also take a look at Hangfire, because I think it's more suited for what you're looking for.

    • @ahmedifhaam7266
      @ahmedifhaam7266 ปีที่แล้ว

      ​@@MilanJovanovicTechHi, why is hangfire more suitable for that?

  • @Saiko1441
    @Saiko1441 ปีที่แล้ว +1

    Thanks for this video!

  • @herveVeve
    @herveVeve ปีที่แล้ว +1

    Thank you for the video, it was interesting and informative.

  • @krzysztofg5840
    @krzysztofg5840 3 หลายเดือนก่อน

    Another great video, glory to Slavic programmers 😁

  • @10Totti
    @10Totti ปีที่แล้ว +2

    Great video!

  • @kaymau5268
    @kaymau5268 ปีที่แล้ว

    Thank you for this helpful video. Glad I found it. I'm a new subscriber!

  • @E_G_
    @E_G_ ปีที่แล้ว +1

    Thank you for the video, love your blog also

  • @victors16811
    @victors16811 ปีที่แล้ว +1

    nice contribution! thank you!

  • @techie607
    @techie607 ปีที่แล้ว +1

    I use to create custom windows service, after some time I moved to "Hangfire"
    I will try this by creating sample project soon

  • @anuragmodi02
    @anuragmodi02 ปีที่แล้ว +2

    what's the difference between using Quartz vs setting up a simple worker service and scheduling with a scheduler something like `Dollar Universe` or `Active Batch Job`? Apart from the fact that using quartz we won't need scheduling tools.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      I'm not familiar with either of the schedulers you mentioned, so can't give you a proper answer

  • @theprantadutta
    @theprantadutta ปีที่แล้ว +2

    do they provide any dashboard like hangfire, and how is this better than hangfire?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +1

      No (I'll make a separate video for Hangfire to compare them)

    • @theprantadutta
      @theprantadutta ปีที่แล้ว

      @@MilanJovanovicTech ok, thanks

  • @luisfortuna4471
    @luisfortuna4471 ปีที่แล้ว +1

    So nice approch. Thanks.

  • @ManiasInc
    @ManiasInc ปีที่แล้ว +1

    Great!! men!! thanks a lot!!👏🏽👏🏽👏🏽👏🏽🎉🎉🎉🎉

  • @kareemolayinka9776
    @kareemolayinka9776 ปีที่แล้ว +6

    Which is better Quartz or HangFire ?

    • @cliffwakefield
      @cliffwakefield ปีที่แล้ว +2

      After watching this video I am glad we are using Hangfire Pro for our purposes.

    • @yardeZ93
      @yardeZ93 ปีที่แล้ว

      @@cliffwakefield Can you elaborate about the reason?

    • @cliffwakefield
      @cliffwakefield ปีที่แล้ว +8

      @@yardeZ93 Hangfire is built upon the concept of persistence layer (we use Redis) so the scheduling of jobs and the executing of jobs can be in completely different processes. Their only point of contact is the job details stored in the persistence layer. It also comes with a Web Console so you can monitor the state of jobs as they are processed, which is especially important when you are running scheduled and recurring jobs. The Web Console can also run in a different process. It also has the concept of batches and continuations which we have found very useful. For example, a parent job that fires up once a day and locates all services without outstanding amounts due, then launches a batch of children jobs that take a payment and generate an invoice. And once the batch is finished it is followed up by a continuation job that sends out a summary via email of the payments taken that day.

    • @cliffwakefield
      @cliffwakefield ปีที่แล้ว +2

      You can also scale out horizontally and vertically with Hangfire. We have a number of worker processes per EC2 Instance (vertical) and then a number of EC2 Instances (horizontal) to increase the level of parallelism we can get with our batches. The Elasticache (Redis) persistence layer can handle these levels of concurrency with ease.

    • @cliffwakefield
      @cliffwakefield ปีที่แล้ว +1

      But to get the more advanced features and official Redis support you need to pay for a license.

  • @majormartintibor
    @majormartintibor ปีที่แล้ว +1

    Nice one!

  • @marcociaschini4616
    @marcociaschini4616 ปีที่แล้ว +1

    I'm wondering what do you think about background jobs from a DDD perspective in a microservices environment. Usually you have some service that deals with some business features of a specific bounded context. And this service usually manages its own database (or at least its own tables). However, it's a common scenario that inside a bounded context there's some need of background jobs that run aside the main microservice. So I'm struggling with this concept: can these background jobs access the same database/tables of the main microservice, cause they are working virtually in the same bounded context? Or they should call some API exposed by the main microservice, so it is the only one that access the persistence layers with aggregates and entities?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Since they are highly coupled anyway, using the same database wouldn't make things much worse.

  • @Saurabh.P
    @Saurabh.P ปีที่แล้ว +1

    What is the difference between this and .NET 6 introduced PeriodicTimer?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      www.milanjovanovic.tech/blog/running-background-tasks-in-asp-net-core

    • @Saurabh.P
      @Saurabh.P ปีที่แล้ว

      @@MilanJovanovicTech Thanks!

  • @jameeliqbal9107
    @jameeliqbal9107 ปีที่แล้ว +1

    thank you for the video on Quartz. Short and precise info provided.
    I want access the same quartz db from 2 apps: 1 desktop app (to manage jobs and triggers) and 1 windows service to run the jobs.
    Is it possible to do this using Quartz?

  • @prathameshshende4
    @prathameshshende4 ปีที่แล้ว +1

    Great tutorial Milan. So there will list of customer Name and DOB where I job will check at start of day and suppose there is dob found then send email to particular customer. So do I put this logic and job will not work whole day.

  • @andrevinicius137
    @andrevinicius137 ปีที่แล้ว +1

    Is a Hangfire vidro coming soon?

  • @georgech.3554
    @georgech.3554 ปีที่แล้ว +1

    What is the best way to prevent concurrency on the scaled instance?

  • @ibrahimhatess
    @ibrahimhatess ปีที่แล้ว +1

    Hi everyone, I have a question about this. I can't use usemicrosoftdependencyinjection.I keep getting this error message "There must be an empty constructor method". How can I use di in my business class?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Give me a repo I can take a look at?

    • @ibrahimhatess
      @ibrahimhatess ปีที่แล้ว

      I can't do this because of the privacy policy. The version I use is 3.7.0 and it is said that this feature is ignored.

  • @AbhishekKhatter
    @AbhishekKhatter หลายเดือนก่อน

    Is there any video for implementing the same with embedding Silkier Quartz UI in it

  • @kelleyfitz-sc8lb
    @kelleyfitz-sc8lb ปีที่แล้ว +1

    Does Quartz work with Maui or only web?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      Does MAUI support IHostedService?

    • @kelleyfitz-sc8lb
      @kelleyfitz-sc8lb ปีที่แล้ว

      @@MilanJovanovicTech after some research, looks like it does not. Thanks

  • @raylin2527
    @raylin2527 3 หลายเดือนก่อน

    wow! hope i could be an awesome software engineer as you are!!

  • @Red-qz4lx
    @Red-qz4lx 7 หลายเดือนก่อน

    I would have made the backgroud job class inherit from the IConfiguration interface directly, so you will have both the job action and it's schedule in the same class, and that it's pretty neat for small operations
    (In case multiple job have the same schedule i would make a parent class)

    • @MilanJovanovicTech
      @MilanJovanovicTech  7 หลายเดือนก่อน

      Inherit from IConfiguration?

    • @Red-qz4lx
      @Red-qz4lx 7 หลายเดือนก่อน

      Shorthand for the IConfigurationOptions
      Of course it's a preference of mine, a lot of people would feel uncofortable having such a multiporpuose class

  • @usmanbacha3449
    @usmanbacha3449 5 หลายเดือนก่อน

    On the production environment, we would typically have multiple containers/pods. How can we make sure always one single pod/container runs all jobs. We dont want all pods/containers to execute/run the jobs parallely. How can we implement this. Please help

    • @MilanJovanovicTech
      @MilanJovanovicTech  5 หลายเดือนก่อน

      Environment variable? Or running jobs in a separate container

  • @june3878
    @june3878 ปีที่แล้ว +1

    I apologize in advance if you mentioned this in the video (my English is very poor so far), what happens if an Exception occurs?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      The task fails 😁 Next one starts as usual... You'd have to handle exceptions, of course

  • @victors16811
    @victors16811 ปีที่แล้ว +1

    Hi Milan, I was able to follow your tutorials successfully, and my job works perfectly in dev, however, after deploying the app in IIS the task does not get executed I am using a job in an API service core net what considerations do I have to take?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      No idea. It should work the same.

    • @victors16811
      @victors16811 ปีที่แล้ว

      ​@@MilanJovanovicTech Interestingly, seems like the IIS put the application in sleep mode and shut the application down, and the schedule, when a new request comes to the API the scheduled start.. now I need to figure out how to keep the application always running, or decouple my API from the Quartz service.. any advice is welcome.. thanks
      -> Application is shutting down...
      ->Scheduler "QuartzScheduler_$_NON_CLUSTERED" shutting down.
      ->Scheduler QuartzScheduler_$_NON_CLUSTERED paused.
      ->Scheduler QuartzScheduler_$_NON_CLUSTERED Shutdown complete.

    • @KenanAmirli-hg5tw
      @KenanAmirli-hg5tw 11 หลายเดือนก่อน

      @@victors16811 On IIS configure you set the always running in the IIS .Default IIS deployed service running when the request come in , but if you configure it always running.

  • @attilaguba856
    @attilaguba856 11 หลายเดือนก่อน

    Nice one! Can you make a video how to make an email email reminder/ like your reservation will start before 48 hours / using Quartz and SendGrid! I would really appreciate it 😊

    • @MilanJovanovicTech
      @MilanJovanovicTech  11 หลายเดือนก่อน +1

      Might be an interesting video to make

    • @attilaguba856
      @attilaguba856 11 หลายเดือนก่อน

      @@MilanJovanovicTech that would be amazing or you can make a guideline how should to do! / for testing might you can reduce a time for 1 minute or make it dynamic like between 1 hour to 60 hours not fixed value ?!

  • @lollol-ko8xx
    @lollol-ko8xx ปีที่แล้ว +1

    Is there a way to configure all instances of IConfigureOptions at once? It would be nice if there was a way that I could pass in the assembly and let the magic happen 😄

  • @sonnyskold5634
    @sonnyskold5634 ปีที่แล้ว +1

    I did this in production but encountered some errors where it stopped running after x amount of time on server. I think it was application pool timeout or something that caused it. Worth noting though, you would have to set timout to 0 (on windows server)

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      That's the problem with your hosting model, not Quartz

    • @sonnyskold5634
      @sonnyskold5634 ปีที่แล้ว +1

      Of course, just thought it was worth mentioning in case someone else ran into it or could help someone before they deploy it :)

    • @ahmedifhaam7266
      @ahmedifhaam7266 ปีที่แล้ว

      What's that mean, hosting model

    • @mallipooalwa9085
      @mallipooalwa9085 ปีที่แล้ว

      If you own the server and can control IIS, you need to remove idle timeout.

    • @mallipooalwa9085
      @mallipooalwa9085 ปีที่แล้ว

      If you don't own the server you'll need to trigger one network call within the timeout so that the app pool doesn't sleep.

  • @ayalamac
    @ayalamac ปีที่แล้ว +1

    Nice as always Milan! I have a question about this. How to create a project that launches different instances of the same routine in quartz? Off course I haven't finished watching this. But I want to ask you asap

  • @nikolaymarchin9296
    @nikolaymarchin9296 6 หลายเดือนก่อน

    Is it possible to trigger a command from the Application layer from a quartz job?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 หลายเดือนก่อน

      It's possible

    • @nikolaymarchin9296
      @nikolaymarchin9296 6 หลายเดือนก่อน

      @@MilanJovanovicTech Thanks for the answer. So I just get an ISender from MediatR in the IJob in the Infrastructure and send a new instance of the command every day for example? Is that an allowed approach when we are using Domain Driven Design?

    • @MilanJovanovicTech
      @MilanJovanovicTech  6 หลายเดือนก่อน

      @@nikolaymarchin9296 Absolutely. Just be mindful that you're sending the command outside an API request, in case you have any dependencies on the HTTP context.

  • @yohanespradono5224
    @yohanespradono5224 3 หลายเดือนก่อน

    it says that UseMicrosoftDependencyInjectionJobFactory is obsolete. how do we change it?

    • @MilanJovanovicTech
      @MilanJovanovicTech  3 หลายเดือนก่อน

      You can freely remove that call, it's no longer needed

  • @Meloga41
    @Meloga41 ปีที่แล้ว +1

    Is it an open source library

  • @coding-in
    @coding-in 2 หลายเดือนก่อน

    I've more than 1 process inside 1 method. Let say 5 process. I want next process run in background so after finished 1st process i want to direct return without waiting other process completed. How?

    • @MilanJovanovicTech
      @MilanJovanovicTech  2 หลายเดือนก่อน

      I didn't understand this

    • @coding-in
      @coding-in 2 หลายเดือนก่อน

      @@MilanJovanovicTech
      Public Task Method(){
      await Process1(); //after this process finished
      Process2();// in background
      Process3();// in background
      Process4();// in background
      Process5();// in background
      Return "success";
      }

  • @alexandrehedreville7609
    @alexandrehedreville7609 12 วันที่ผ่านมา

    hi Milan, I am trying to run the code on a console app, but job never start. can you explain how to get it running on console app

    • @MilanJovanovicTech
      @MilanJovanovicTech  11 วันที่ผ่านมา

      No idea why

    • @alexandrehedreville7609
      @alexandrehedreville7609 9 วันที่ผ่านมา

      ​@@MilanJovanovicTech

    • @alexandrehedreville7609
      @alexandrehedreville7609 9 วันที่ผ่านมา

      After investigating, I found the problem and two possible solutions:
      1. Use a HostBuilder within the console,
      or
      2. Create your own QuartzHostedService with your own factory to resolve jobs, etc.
      Something that doesn't help much is that when Quartz is unable to build the dependencies for a job's constructor, it simply does nothing and doesn't throw any error.

  • @ASIMKHAN-ig9eo
    @ASIMKHAN-ig9eo 11 หลายเดือนก่อน

    What do you think will Quartz be a good option or using built-in background jobs provided by aspnetcore ?

  • @souravsingha3340
    @souravsingha3340 9 หลายเดือนก่อน

    Please make video about best practice with postgres datetime type. Querying different scene.. With different time zone issue

    • @MilanJovanovicTech
      @MilanJovanovicTech  9 หลายเดือนก่อน

      Just use UTC 😅

    • @souravsingha3340
      @souravsingha3340 9 หลายเดือนก่อน

      @@MilanJovanovicTech i already used.. Actually problem is timespan grouping with dateonly,timeonly..

    • @souravsingha3340
      @souravsingha3340 9 หลายเดือนก่อน

      I got problem when i querying data 2024-03-01 at midnight. Its convert it in utc supposed 2024-02-29.. If query only datey only data. What happened explain this situation??🤔🤔🤔please

  • @sunzhang-d9v
    @sunzhang-d9v ปีที่แล้ว +1

    [Obsolete("MicrosoftDependencyInjectionJobFactory is the default for DI configuration, this method will be removed later on")] ?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      The one used here isn't obsolete

    • @sunzhang-d9v
      @sunzhang-d9v ปีที่แล้ว +1

      我知道,但是最新的包过期了,RabbitMq那个视频使用的包也过期了,能更新一下视频吗@@MilanJovanovicTech

  • @jalalmalekpour
    @jalalmalekpour 9 หลายเดือนก่อน

    thanks for share videos

  • @thedjnute
    @thedjnute 8 หลายเดือนก่อน

    using this but only 1 of my job gets registered

  • @pepiwi
    @pepiwi 8 หลายเดือนก่อน

    muy bueno crack

  • @jerryjeremy4038
    @jerryjeremy4038 ปีที่แล้ว +1

    +1 like, +1 sub. Thanks man

  • @amerkovac5247
    @amerkovac5247 8 หลายเดือนก่อน

    mašina čovjek

  • @AmericanEnglishAcc
    @AmericanEnglishAcc ปีที่แล้ว +3

    Quartz is just overall inferior to Hangfire. It's extremely verbose and doesn't have built-in, default support for concurrency or distributed environments.

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว +2

      Which is why it's great for simple recurring tasks. You don't need a bulldozer to drill a small hole.

    • @GreyTaube
      @GreyTaube ปีที่แล้ว

      You did not dig many holes have you? Better to dig a small hole in minutes with no worries versus doing it by hand.
      There are actually arguments for using Quartz, but the video nor your comment mention them.

    • @ahmedifhaam7266
      @ahmedifhaam7266 ปีที่แล้ว

      ​@@GreyTaubeI'm actually really interested, when would you need to use Quartz, over hangfire.
      I can see why something like Serilog (maybe with seq) is soooo much better than built in ILogger or even Elmah.
      But I am still stuck between what background task scheduler to use.. Hnagfire seems a Lil simpler, comes with dashboard, idk.. everyone recommends Quartz though but I don't yet understand why.

  • @Paul-uo9sv
    @Paul-uo9sv ปีที่แล้ว +1

    Which country was quartz developed in?

    • @MilanJovanovicTech
      @MilanJovanovicTech  ปีที่แล้ว

      No idea

    • @Paul-uo9sv
      @Paul-uo9sv 11 หลายเดือนก่อน

      @@MilanJovanovicTech Tampere, Pirkanmaa, Finland