HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.43k stars 1.71k forks source link

Hangfire with Aspire integration #2408

Open meghuizen opened 6 months ago

meghuizen commented 6 months ago

What I think would be a killer combo is having Hangfire integration in Aspire. The scenario I would like to see is that you have Aspire running with multiple Hangfire workers on different projects running in Aspire. The Hangfire dashboard as plugin part of the Aspire dashboard, which will give an overview on all the Hangfire jobs on all the Hangfire workers running in Aspire. Also the telemetry and logging being visible from Aspire.

odinserj commented 6 months ago

Looks indeed interesting, but need to understand its component model first. It seems to me that it's possible to integrate Hangfire with its current capabilities, since Aspire is likely using ASP.NET Core infrastructure, so it is likely to see the logs in Aspire dashboard anyway. But more detailed integration would be useful to have.

adanbrownpaca commented 5 months ago

We should make this simpler - we should add the ability for Hangfire to simply use a DB on the container provide by aspire. Do do this it needs to be able to install the DB seamlessly:

Hangfire Project: builder.AddSqlServerClient("BackgroundJobsDb");

Aspire: var sqldbserver = builder.AddSqlServer("DbServer"); var backgroundjobsdb = sqldbserver.AddDatabase("BackgroundJobsDb"); builder.AddProject("backgroundjobs") .WithReference(backgroundjobsdb);

This way the Db gets installed on the local development container and initialized with the schema. Then, this simplifies deployment to Azure.

arielmoraes commented 3 months ago

Let's not forget Aspire provides packages for the client too. So all the goodies like OpenTelemetry, Health Checks, and more are expected to be provided out-of-box.

sagarok commented 2 months ago

We should make this simpler - we should add the ability for Hangfire to simply use a DB on the container provide by aspire. Do do this it needs to be able to install the DB seamlessly:

Hangfire Project: builder.AddSqlServerClient("BackgroundJobsDb");

Aspire: var sqldbserver = builder.AddSqlServer("DbServer"); var backgroundjobsdb = sqldbserver.AddDatabase("BackgroundJobsDb"); builder.AddProject("backgroundjobs") .WithReference(backgroundjobsdb);

This way the Db gets installed on the local development container and initialized with the schema. Then, this simplifies deployment to Azure.

Would be very useful. Any chance on that?

sgryphon commented 4 weeks ago

At a minimum, I am looking at adding Activity (trace/span) support, for Producer/Consumer, similar to MassTransit. (Because Hangfire doesn't integrate with activity, so has no trace ID).

Once tracing is working, logs should be automatically correlated (if they go through normal .NET ILogger).

Metrics can be added later.

sgryphon commented 3 weeks ago

I've put up a PR for the observability aspects, to start new activities for job producer and consumer. https://github.com/HangfireIO/Hangfire/pull/2460

This follows .NET standards (based on OpenTelemetry), so observability can easily be added (just add the named source to OTel so it creates a listener and activates the integration). This will cover the trace and logging aspects.

(Metrics will need to be done separately).