Superb ! I been facing this problem lot a time. i was not able to inject scoped and transient dependency into singleton. It's too late to know but finally i got my answer. Keep tuned us.
I believe this tutorial will help me implement the MS Azure Service Bus Queue as a background service and via IServiceProvider Dependency Injection use repository pattern scoped service to save queue messages to my entityframework SQL Server DB which I will be able to read via my API controller and display to a frontend via API calls using react js. I hope this works...
Thank you Sachini. Do check out the full series here ru-vid.com/group/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP I am sure you will like them too! Do let me know in case you get to watch them 😀
Nice. Thank you. Unit test cases on background services as well next time. Will share nuget packages on which videos could be created. I forgot about that.
Thanks, Rahul; your content is always meaningful and applicable to real solutions. Keep up the great work!! Can you make one with scheduled tasks in background services, please?
Thank you 😀 For logging ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-dxBlBltEDRs.html Does that help? What specifically are you looking for with collections?
Thank you Aravind. Do check out the full series here if you haven't already ru-vid.com/group/PL59L9XrzUa-nqfCHIKazYMFRKapPNI4sP Feel free to let know if you have specific topic suggestions.
Hi Rahul, thanks for your video!! In scenarios where the application is abruptly closed, does it exists a workaround how to handle those abruptly closings?
It's best to use external queues for critical processing and avoid the background tasks for this as you might loose information. What is your scenario you are using this for?
@@RahulNath what type of external queues do you refer? Is a hypothetical scenario of thousand of data to process daily, maybe for example financial institution usually process thousands of records to process loans. I was thinking of batch data split in multiple jobs/tasks ?
@@diegomelgar2696Azure Service Bus Queue, AWS SNS, SQS , Rabbit MQ etc depending on where and how your application is hosted/managed. I have some introduction to this in my Messaging series here ru-vid.com/group/PL59L9XrzUa-ku74pfBcy4f3tigwfzGUrG For critical processing I wouldn't depend on Background Tasks.
Its a hosted service in WebApp, so if I host that web app in Azure? How will the background task behave? So we duplicate background tasks when we scale web app? So background task should manage some locks to avoid duplication? Any thoughts?
Sorry for delay in getting back. Yes as you scale there will be multiple instances. What problem are you trying to solve using background tasks? Using Azure Functions might be another way if you want to control the number of instances and always want only one instance.
Glad you like it and thank you for the lovely caring comment. I record all my videos during that time (4-5) 😀 (That's when house is least noisy). Wrote about it here if you are interested. twitter.com/rahulpnath/status/1393813849933897737?s=20
Hi! I want to save excel files into the local server once every year using scheduler so may i know how to call the excel generating api from my existing controller in my scheduler class
Serious question. Someone told me that these tasks are utterly unreliable in Azure. Do you have any experience using them in App Services in Azure? Cheers
Yes I've used this in production in Azure App Service and have had no issues. Depends a lot on how they have used/what error handling mechanisms they have in place. Another option for you would be to make it a web job. What is your scenario?
Nice Tutorial! I want to build a api that start and stop the background task .how can I do that ?if so,than is it the wise way to start and stop the background task?
the background job should be running as long as your web app is up and running. Otherwise I would be looking at Azure Function instead of using a Background Task. Does that help?
I don't have an example for IIS - there are a few on my channel to deploy to Azure Web App bit.ly/azure-devops-series
2 года назад
Good job with the tutorial, could you create some on how to use the QUARTZ library in net core, since the ones that are currently there are very confusing and I think you would make them much easier to understand.
Glad you like the video and Great suggestion! I will add this to my list. I have a blog post from a while back here using Quartz in case it helps www.rahulpnath.com/blog/windows-service-using-topshelf-quartz-and-autofac/
Hi Rahul, thanks for a another brilliant video. I’m looking for a azure devops ci/cd example for the new Logic Apps Standard. Do you know of a good resource for this? Not looking for entire IaC, rather just continuously build and deploy on commit
@@RahulNath Hi Rahul, the logic app standard sku just recently went GA with MS Build. Previous devops story for logic app was different. The new logic app standard is running on the azure functions runtime, so it is very similar to app services in terms of ci/cd. But I can’t find a good example as it’s so new.
Another great video! I knew about Background service but did not know the limitation you demoed. Thank you for pointing that. Also, You mentioned that there is a new video coming for exception handling for Background services, can you please add a link for that?.
Sure you can - but if the app is down it won't run, so keep that in mind. Might look at Azure Function on a Timer trigger as well depending on the task and how important it is etc.
Thank you Rohan for the suggestion. I have added this to my list. But that will not be coming out immediately. Mostly because I have not explored much of Blazor 😀
#RahulNath, Hi Sir I have developed this task and its running on my machine,But when i publish on IIS Server its showing Swagger page and jobs are not storing and sending into database,I have watched so many solution nothing is working.Please can you help.Lot of setting i have trying.
Very nice tutorial ☺️ just i have a question that can we run hosted service as per own events. e.g - when task A is completed then we need to fire background service to execute Task B ?
Yes you can use Channels library for this learn.microsoft.com/en-us/dotnet/core/extensions/channels But depends what kind of tasks and be aware it will be in memory. If you provide more context on the problem I could give some suggestions.
Thank You for reply!! I have to read an excel having 20k rows and after reading this, we need to execute some business logic for each row. 1. upload an Excel 2. Reading Rows and storing in DB. 3. click on the start process button. 4. Now we will read all the data from the table and perform some tasks (Business logic) in the background for each row (Total around 20k rows). 5. Tech Using .Net Core 3.1
@@shashankpandey1019 I would use messaging for this - so publish a message for each row and process it independently. You can also use background tasks. Once you save the excel records to database signal the background worker using Channels or you can use polling from background job for new jobs/rows in the database. A Message Queue is ideal for these scenarios instead.
Depends on where you are hosting and what you are doing in the Background Tasks. If it's resource heavy you can decouple it to a Function/Lambda (depending on what your hosting platform is).
Yes you could, but if you are on Azure I might use a Web Job or an Azure Function for that. But that said, you could very well do that in BackgroundTask as well
Sorry for the delay. Yes you can exit the loop and run only once or based on your conditions. the first job I show in the example closes down after first execution. If you can give more details on your use case I could suggest something.
@@RahulNath my use case is i created a background service to subscribe a kafka topic. As you said the while loop in the background service exist only when application goes to shutdown. My requirement is to create an endpoint or something that control the start and stop of background task. I don't know it is possible. If its possible please reply.
Best to use some external packages for that - Have a look at Quartz.net www.quartz-scheduler.net/ Hangfire etc www.hangfire.io/ Or if you can pull them out into serverless functions (Azure Functions, Lambda etc) if you are on cloud. Let me know if that helps.
@@RahulNath okay, smh it's working now. But not instantly when I start the process but only after I did a first request to the backend over the frontend?! So if I just start my API, the worker won't instantly start. As I log in from the frontend a request will be sent to the API (just casual stuff) and then the worker starts. (After a request)