VOOZH about

URL: https://www.nuget.org/packages/Hangfire.Community.CarbonAwareExecution/

⇱ NuGet Gallery | Hangfire.Community.CarbonAwareExecution 2.3.1




Hangfire.Community.CarbonAwareExecution 2.3.1

dotnet add package Hangfire.Community.CarbonAwareExecution --version 2.3.1
 
 
NuGet\Install-Package Hangfire.Community.CarbonAwareExecution -Version 2.3.1
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hangfire.Community.CarbonAwareExecution" Version="2.3.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hangfire.Community.CarbonAwareExecution" Version="2.3.1" />
 
Directory.Packages.props
<PackageReference Include="Hangfire.Community.CarbonAwareExecution" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hangfire.Community.CarbonAwareExecution --version 2.3.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Hangfire.Community.CarbonAwareExecution, 2.3.1"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Hangfire.Community.CarbonAwareExecution@2.3.1
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hangfire.Community.CarbonAwareExecution&version=2.3.1
 
Install as a Cake Addin
#tool nuget:?package=Hangfire.Community.CarbonAwareExecution&version=2.3.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Carbon Aware Computing Hangfire Extension

Overview

A Hangfire extension to schedule tasks with carbon awareness in mind. The best point in time is calculated based on emission forecasts to get a window with a minimal grid carbon intensity.

Installation

Hangfire.Community.CarbonAwareExecution is available as a NuGet package. You can install it using the NuGet Package Console window:

Install-Package Hangfire.Community.CarbonAwareExecution

After installation add the extension to the Hangfire configuration. It extends the AddHangfire-Extension to add additional dependencies.

builder.Services.AddHangfire(configuration => configuration
 .UseCarbonAwareExecution(new CarbonAwareDataProviderOpenData(), ComputingLocations.Germany)
);

Usage

To enable carbon awareness for a specific job, add a CarbonAwareExecution parameter to the method called by hangfire. The parameter defines the maximum acceptable delay for the job. Pass null to disable carbon aware shifting. This works for all kind of hangfire jobs, namly fire and forget, scheduled and recurring jobs. See JobController for more examples.

public static class HangfireActions
{
 public static void CarbonAwareJob(/*your functional parameters*/ CarbonAwareExecution? carbonAware) => ...;
}

Fire and Forget tasks

Setup maximum delay and the estimated task duration. The extension will do a best effort to get a window with the estimated task duration and minimal grid carbon intensity. When no window can be detected, the task is enqueued immediately.

//use the extension methods
IBackgroundJobClient client = GetBackgroundJobClient();
client.Enqueue(
 () => HangfireActions.CarbonAwareJob(
 "Hello world from Hangfire!. Enqueue carbon aware jobs.",
 new CarbonAwareExecution(TimeSpan.FromHours(2), TimeSpan.FromMinutes(5))
));

//or use the static versions
BackgroundJob.Enqueue(
 () => HangfireActions.CarbonAwareJob(
 "Hello world from Hangfire!. Enqueue carbon aware jobs.",
 new CarbonAwareExecution(TimeSpan.FromHours(2), TimeSpan.FromMinutes(5))
)); 

Delayed tasks

Setup the earliest execution time, the maximum delay and the estimated task duration. The extension will do a best effort to get a window with the estimated task duration and minimal grid carbon intensity. When no window can be detected, the task is scheduled as desired.

//use the extension methods
IBackgroundJobClient client = GetBackgroundJobClient();
client.Schedule(
 () => HangfireActions.CarbonAwareJob(
 "Hello world from Hangfire!. Schedule carbon aware jobs",
 new CarbonAwareExecution(TimeSpan.FromHours(2), TimeSpan.FromMinutes(5))),
 TimeSpan.FromMinutes(20)
);

//or use the static versions
BackgroudJob.Schedule(
 () => HangfireActions.CarbonAwareJob(
 "Hello world from Hangfire!. Schedule carbon aware jobs",
 new CarbonAwareExecution(TimeSpan.FromHours(2), TimeSpan.FromMinutes(5))),
 TimeSpan.FromMinutes(20)
);

Recurring tasks

Setup the maximum execution delay after planned schedule time and the estimated task duration. The extension will do a best effort to get a window with the estimated task duration and minimal grid carbon intensity. When no window can be detected, the task is scheduled as desired.

//use the extension methods
IRecurringJobManager manager = GetRecurringJobManager();
manager.AddOrUpdate(
 "daily",
 () => HangfireActions.CarbonAwareJobAsync("Hello world from Hangfire!. Recurring carbon aware jobs",
 new CarbonAwareExecution(TimeSpan.FromHours(3), TimeSpan.FromMinutes(5))),
 "2 0 * * *"
);

//or use the static versions
RecurringJob.AddOrUpdate(
 "daily",
 () => HangfireActions.CarbonAwareJobAsync("Hello world from Hangfire!. Recurring carbon aware jobs",
 new CarbonAwareExecution(TimeSpan.FromHours(3), TimeSpan.FromMinutes(5))),
 "2 0 * * *"
);

The Hangfire Carbon Aware Extension will prevent the execution of the current instance of the recurring job. It is calculation a execution window with minimal carbon impact and the schedule that task. In the dashboard you will see the notice that the job was executed and a newly planned task.

Fallback

If your computing location is outside Europe or you need other forecasts the WattTime data provider may be useful. You need a valid WattTime account to use the data provider.

builder.Services.AddHangfire(configuration => configuration
 .UseCarbonAwareExecution(
 () => new CarbonAwareExecutionOptions(
 new CarbonAwareDataProviderWattTime(userName, password), 
 ComputingLocations.Germany))
 );

Extensibility

For custom forecasts or scenarios you don't want the build in provider add a own data provider. You may extend the abstract base class CarbonAwareDataProvider or use the CarbonAwareDataProviderWithCustomForecast. A WattTime data provider is implemented as well.

Methodology

Hangfire.Community.CarbonAwareExecution Extension makes use of the Carbon Aware SDK a Green Software Foundation Project. There are some extensions to the SDK to use cached offline data sources in our fork.

The emission forecast data are uploaded periodically to a Azure Blob Storage for a given grid region and are public (e.g. for Germany https://carbonawarecomputing.blob.core.windows.net/forecasts/de.json).

To avoid unnecessary processing only a few grid regions are active. Currently de, fr, at, ch

  • Europe (without UK): The API from https://www.energy-charts.info/ are used. The data is the share of renewable energy to the total power production. The origin data source is from entso-e. The data is generated every day at 19:00+01 for the next day. After 19:00+01 the maximum forecast is next day 24:00+01.

  • United Kingdom: The API from https://carbonintensity.org.uk/ are used. The data is the carbon intensity. The data is generated periodically .

We will provide data for the european grid regions. Please send a mail to am@bluehands.de if you need for one of the inactive regions.

For forecasts outside of europe you may use the WattTime provider with an active account.

To shift job executions in Hangfire an IElectStateFilter is used to calculate the delay at enqueue time and reschedule the background job once if it was not rescheduled before. Use can actually use the ShiftJobFilter<TParameter> filter to implement custom shifting logic in a very simple way.

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 was computed.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 was computed.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.3.1 2,160 3/18/2025
2.2.1 296 3/13/2025
2.2.0 297 3/12/2025
2.1.1 297 3/12/2025
2.1.0 235 2/19/2025
2.0.0 277 2/11/2025
1.0.3 333 6/16/2024
1.0.2 447 12/4/2023
1.0.1 399 5/1/2023
1.0.0 408 5/1/2023