We are leaving Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Hangfire for this architecture

Hello everyone,

I have read the hangfire documentation and search through a lot of blog posts and answers on SO.
I just want to be sure that hangfire will work for our use case.

We currently have a couple of jobs (console apps) that perform some business functions. Most of these jobs run daily.

We are looking to integrate hangfire to simplify the task of running and maintaining these jobs.

To achieve this, we want to use the console apps as clients and also have a windows service that has HangFire.Server installed.

The challenge is in keeping the clients running.

We started by scheduling the job and running the server in the same console application. this worked fine.

We scheduled some more jobs and commented out the part to schedule jobs, leaving only the server code. When we run it, we go this error:

Retry attempt 1 of 10: Cannot dynamically create an instance of type 'El…

Maybe we are doing it the wrong way, I can’t tell.

Also to note, the console app is a .NET 6 application and we used DI. But even after following the solutions on numerous blog posts and SO links, it still throws the error.

Any help would be appreciated.

I’m not sure what 'El... is. If that is the job then the job definition has to either live in the server application/service or a library that the server application/service references.

If you want a client and server then you would likely have the job definition in a library that can be referenced by both the client and server applications. You can also define an interface that the console uses to queue the job and use DI to map the interface to an implementation on the server.

I’m not sure what keeping the client is getting you in your example. Hangfire has recurring jobs that use CRON for scheduling. You can easily setup recurring jobs in the server and not need the client(s).

Thanks for the reply @aschenta

You mentioned that

the job definition has to either live in the server application/service or a library that the server application/service references.

We have a lot of clients and we are using just one server to process the jobs.
Also from all examples I have seen especially the ASP.NET ones, the server does not have a reference to the client.

Having the implementation of the job on the server would make the server bloated for us.

Sorry if I am not making much sense, but I am still trying to wrap my head around the whole thing.

Thanks

The server doesn’t need to reference the client, just the job. The server must know what the job is as it needs to instance and run it along with any dependencies.

Thanks @aschenta
If it’s not too much of a ask, can I paste some of my code here so you can see what I am doing wrong. I am thinking of going the route you suggested where you suggested I create a library of job definitions including dependencies.
I have no experience in this and would appreciate any pointers