I've been faced with a scenario where we need to do some heavy processing (create zip files) based on data both from custom db-tables and some data stored as Umbraco content (v8). Since the tasks are very heavy and will be long running we don't want to use a single web request to perform the processing. We're looking at something like hangfire, a windows service or a console app - either way the process will not be in the "web context".
My problem is that I have some repositories that loads data from the content cache returning IPublishedContent that we convert into our domain model objects, something like:
using (var ctx = _contextFactory.EnsureUmbracoContext())
{
var myContent = ctx.UmbracoContext.Content.GetByKey(contentKey);
return MapToDomainModel(myContent));
}
Given this scenario I was hoping for a way to use the Umbraco Content Cache outside of the web context (in a console app or in a Hangfire job). I'm not sure if this is even possible or recommended? Have anyone tried this with success or does anyone have any experience around this?
It does not really matter if the startup of this process is slow since our background task will only run once every week or so.
One solution that I've been thinking about is to perform a API-call from my background-process to get the data that I need - that would also work but I wanted to reach out here before I choose my path forward.
Can I ask if you progressed further with this? I find myself in the same situation. I'm thinking an API call to the Umbraco www instance is perhaps the only (or at least by far and away the simplest) way.
When I posted the question I was thinking about using Hangfire with a separate Windows Service as the ”processor”, but it’s also totally fine to host Hangfire inside the web application process.
For the project we worked on this “trade off” was okey at the moment but if we need to scale further we might have to change this.
Since we’re running inside the web app process we can just use the DI from Umbraco and pass any dependencies we want to our jobs so we choose that path.
If you must run out of process I don’t have much to share but if you want to try running inside the web app let me know and I’ll share some pointers and code :)
Console App with access to the published content cache
Hi!
I've been faced with a scenario where we need to do some heavy processing (create zip files) based on data both from custom db-tables and some data stored as Umbraco content (v8). Since the tasks are very heavy and will be long running we don't want to use a single web request to perform the processing. We're looking at something like hangfire, a windows service or a console app - either way the process will not be in the "web context".
I've seen some examples of how to use the Services APIs from a console app like this for example: https://github.com/sitereactor/umbraco-console-example
My problem is that I have some repositories that loads data from the content cache returning IPublishedContent that we convert into our domain model objects, something like:
Given this scenario I was hoping for a way to use the Umbraco Content Cache outside of the web context (in a console app or in a Hangfire job). I'm not sure if this is even possible or recommended? Have anyone tried this with success or does anyone have any experience around this?
It does not really matter if the startup of this process is slow since our background task will only run once every week or so.
One solution that I've been thinking about is to perform a API-call from my background-process to get the data that I need - that would also work but I wanted to reach out here before I choose my path forward.
Cheers!
Hi Marcus,
Can I ask if you progressed further with this? I find myself in the same situation. I'm thinking an API call to the Umbraco www instance is perhaps the only (or at least by far and away the simplest) way.
Thanks, Mark
Hi Mark!
When I posted the question I was thinking about using Hangfire with a separate Windows Service as the ”processor”, but it’s also totally fine to host Hangfire inside the web application process.
For the project we worked on this “trade off” was okey at the moment but if we need to scale further we might have to change this.
Since we’re running inside the web app process we can just use the DI from Umbraco and pass any dependencies we want to our jobs so we choose that path.
If you must run out of process I don’t have much to share but if you want to try running inside the web app let me know and I’ll share some pointers and code :)
Cheers!
is working on a reply...