Search code examples
c#hangfirewebapi

Queue tasks with Hangfire on a different server to where they are executed?


We are creating a website using propriety closed source CMS software, and I need to run a long-running task on the webserver to import products into the store (with code built into our CMS), but I'd like too queue these long running tasks on a different server, is this possible?

for example:

Server 1 :

// not shown: set "DbConnection" as our sql connection somehow?
BackgroundJob.Enqueue(() => Console.WriteLine("Hello, world!"));

Server 2:

GlobalConfiguration.Configuration.UseSqlServerStorage("DbConnection");
_backgroundJobServer = new BackgroundJobServer();

so that "Hello, World1" would be executed on Server 2 instead of server 1. Is this possible?


Solution

  • Only create background job servers on Server2, but not on Server1. If both Server1 and Server2 use the same storage settings, you can schedule jobs on Server1 but they are only executed on Server2.