I currently have 2 physical windows servers which runs the exact same copy of an asp.net core 6 application with a load balancer in front of them. One server is the primary server and the second is a DR server incase the first one fails.
Since I have jobs/background jobs which are dependent on the server, I would like to configure the the primary server should always run all jobs, and the secondary server should only start executing jobs in the event the first server is unavailable.
I couldn’t find any other examples/implementations where this is being done for separate physical servers, only for same physical server. The idea I had was to register unique queues for each server e.g Queue “primary” for primary server and queue “secondary” for secondary server but I’ve run into a issue with creating unique queues for specific servers.
The application would then register jobs based on whether primary is available or not. Example code I would use to determine which queue and essentially which server to execute the job on below:
public static void EnqueueWithFallback(Expression<Action> jobAction, string primaryQueue, string fallbackQueue){
try{
BackgroundJob.Enqueue(primaryQueue, jobAction);
}catch(Exception){
BackgroundJob.Enqueue(fallbackQueue, jobAction);
}
}
Any help would be great or if there’s a better way to implement a solution for prioritizing execution of jobs based on physical server availability. Also, we have pipelines to deploy code from master branch only, so having 2 separate code bases for registering the different queues will not be viable.