Arcus BackgroundJobs

website·Indexed 32 days ago

https://background-jobs.arcus-azure.net/

A collection of common background tasks to strengthen applications, including libraries for securely receiving CloudEvents, automatically invalidating Azure Key Vault secrets, rotating credentials, and interacting with Databricks for insights and job metrics. Available via NuGet, with documentation covering versions v0.1 through v0.4.0.

Tokens
11.2K
Snippets
44
Records
57
Agent score
56%

What's inside Arcus BackgroundJobs

  1. Overview of Securely Receiving CloudEvents with Arcus

    The Arcus.BackgroundJobs.CloudEvents library (v0.4.0) allows workloads to asynchronously process CloudEvents from other components without exposing a public endpoint. It achieves this by using an Azure Service Bus Topic to receive messages, which are then processed by a background job.
  2. Overview of Arcus BackgroundJobs

    Arcus BackgroundJobs is a collection of common, reusable background tasks designed to strengthen applications. Examples of provided functionality include automatic secret invalidation of Azure Key Vault secrets and publishing events to Azure EventGrid when a client secret in Azure is potentially expired.
  3. Automatically restart Service Bus message pump on Azure Key Vault credential rotation

    v0.3
    The Arcus.BackgroundJobs.KeyVault library provides an extension that automatically restarts a message pump when its credentials in Azure Key Vault are updated. Instead of relying solely on authentication exceptions, it uses a background job to poll for SecretNewVersionCreated events on an Azure Service Bus Topic. When a new version of the secret is detected, the library retrieves the latest connection string and restarts the message pump.
  4. Automatically invalidate cached Azure Key Vault secrets

    v0.2

    The Arcus.BackgroundJobs.KeyVault library provides a background job that automatically invalidates cached secrets in an ICachedSecretProvider instance. It works by subscribing to the SecretNewVersionCreated event of an Azure Key Vault resource, which sends events to an Azure Service Bus Topic that the background job processes.

    To implement this automation, the following Azure resources are required:

    • Azure Key Vault instance
    • Azure Service Bus Topic
    • Azure Event Grid subscription for SecretNewVersionCreated events configured to send to the Azure Service Bus Topic.
  5. Automatically invalidate cached Azure Key Vault secrets

    v0.3

    The Arcus.BackgroundJobs.KeyVault library provides a background job that automatically invalidates cached secrets from an ICachedSecretProvider instance. It works by subscribing to the SecretNewVersionCreated event of an Azure Key Vault resource via Azure Event Grid, which sends events to an Azure Service Bus Topic for processing by the background job.

    Required Azure Resources:

    • Azure Key Vault instance
    • Azure Service Bus Topic
    • Azure Event Grid subscription for SecretNewVersionCreated events targeting the Service Bus Topic.
  6. Automatically invalidate Azure Key Vault secrets

    The Arcus.BackgroundJobs.KeyVault library (v0.4.0) provides a background job that automatically invalidates cached secrets from an ICachedSecretProvider instance. It works by subscribing to the SecretNewVersionCreated event of an Azure Key Vault resource, which sends events to an Azure Service Bus Topic that the background job processes.

    Required Azure Resources:

    • Azure Key Vault instance
    • Azure Service Bus Topic
    • Azure Event Grid subscription for SecretNewVersionCreated events configured to send to the Azure Service Bus Topic.
  7. Automatically invalidate Azure Key Vault secrets using Arcus.BackgroundJobs.KeyVault

    v0.1

    The Arcus.BackgroundJobs.KeyVault library provides a background job that automatically invalidates cached secrets from an ICachedSecretProvider instance. It works by subscribing to the SecretNewVersionCreated event of an Azure Key Vault resource via Azure Event Grid, which forwards events to an Azure Service Bus Topic for processing by the background job.

    Required Azure Resources:

    • Azure Key Vault instance
    • Azure Service Bus Topic
    • Azure Event Grid subscription for SecretNewVersionCreated events configured to send to the Azure Service Bus Topic.
  8. Monitor Azure AD client secret expiration with Arcus Background Jobs

    The Arcus.BackgroundJobs.AzureActiveDirectory library provides a background job that periodically queries the Microsoft Graph API to check for Azure Active Directory application client secrets that have expired or are approaching expiration. When a secret is found to be expired or near expiration (based on a configurable threshold), the job publishes either a ClientSecretExpired or ClientSecretAboutToExpire CloudEvent to Azure EventGrid.
  9. Automatically restart Service Bus message pump on Azure Key Vault credential rotation

    The Arcus.BackgroundJobs.KeyVault library extends the message pump to automatically restart when credentials stored in Azure Key Vault are updated. This is achieved by a background job that polls for SecretNewVersionCreated events on an Azure Service Bus Topic. When a new event is received, the pump retrieves the latest connection string and restarts to authenticate with the new credentials.
  10. Implement a secure CloudEvent receiver using CloudEventBackgroundJob

    v0.1
    The Arcus.BackgroundJobs.CloudEvents library allows workloads to process CloudEvents asynchronously via an Azure Service Bus Topic, removing the need to expose a public endpoint. To implement a receiver, create a class that inherits from CloudEventBackgroundJob. This base class automatically handles the creation and deletion of the topic subscription when the job starts and stops. The core logic for processing events is implemented by overriding the ProcessMessageAsync method.
    using Arcus.BackgroundJobs.CloudEvents;
    using CloudNative.CloudEvents;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Logging;
    
    public class MyBackgroundJob : CloudEventBackgroundJob
    {
        public MyBackgroundJob(
            IConfiguration configuration,
            IServiceProvider serviceProvider,
            ILogger<CloudEventBackgroundJob> logger) : base(configuration, serviceProvider, logger)
        {
        }
    
        protected override async Task ProcessMessageAsync(
            CloudEvent message,
            AzureServiceBusMessageContext messageContext,
            MessageCorrelationInfo correlationInfo,
            CancellationToken cancellationToken)
        {
            // Process the CloudEvent message here
        }
    }
  11. Implement a custom CloudEvent message handler

    v0.3
    To process incoming CloudEvents, implement the IAzureServiceBusMessageHandler<CloudEvent> interface. Register the handler during the background job configuration using the .WithServiceBusMessageHandler<THandler, TMessage>() extension method.
    using Arcus.Messaging.Abstractions;
    using Arcus.Messaging.Abstractions.ServiceBus;
    using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling;
    using CloudNative.CloudEvents;
    using Microsoft.Extensions.Logging;
    using Microsoft.Extensions.DependencyInjection;
    
    // 1. Define the handler
    public class MyCloudEventMessageHandler : IAzureServiceBusMessageHandler<CloudEvent>
    {
        private readonly ILogger _logger;
    
        public MyCloudEventMessageHandler(ILogger<MyCloudEventMessageHandler> logger)
        {
            _logger = logger;
        }
    
        public async Task ProcessMessageAsync(
            CloudEvent message,
            AzureServiceBusMessageContext messageContext,
            MessageCorrelationInfo correlationInfo,
            CancellationToken cancellationToken)
        {
            _logger.LogInformation("Processing CloudEvent message");
        }
    }
    
    // 2. Register the handler in Startup
    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCloudEventBackgroundJob(...)
                    .WithServiceBusMessageHandler<MyCloudEventMessageHandler, CloudEvent>();
        }
    }
  12. Set up Azure infrastructure for App Configuration auto-refresh

    To enable automatic notification of IConfiguration changes, you must configure an event-driven pipeline where Azure App Configuration sends events to an Azure Service Bus Topic, which the Arcus background job then monitors.

    Required infrastructure:

    1. An Azure App Configuration resource.
    2. An Azure Service Bus Topic resource.
    3. An event subscription on the App Configuration resource configured to send events to the Service Bus Topic.