TimeToFish 1.1.2

dotnet add package TimeToFish --version 1.1.2
NuGet\Install-Package TimeToFish -Version 1.1.2
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="TimeToFish" Version="1.1.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TimeToFish --version 1.1.2
#r "nuget: TimeToFish, 1.1.2"
#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.
// Install TimeToFish as a Cake Addin
#addin nuget:?package=TimeToFish&version=1.1.2

// Install TimeToFish as a Cake Tool
#tool nuget:?package=TimeToFish&version=1.1.2

TimeToFish

Library for simple handling of time events to implement crontab like functionality using azure service bus events. Inspired by Passage of time event pattern

The library consist of two extension methods on the IServiceCollection interface. </br> IServiceCollection ConfigureTimerJobs(this IServiceCollection services, string connectionString, string serviceName, params (Type jobType, string subscriptionName)[] jobs)

IServiceCollection ConfigureTimerJobs(this IServiceCollection services, TokenCredential tokenCredential, string fullyQualifiedNamespace, string entityName, string serviceName, params (Type jobType, string subscriptionName)[] jobs)

  • connectionString: The connection string to the Azure Service Bus topic where the TimeHasPassed events are published
  • serviceName: Unique name of the service
  • jobs: Array of tuples containing jobType and subscriptionName. jobType is the type of the class implementing the event handler/the job. subscriptionName is the name of a subscription on the Topic. The topic should be configured to filter on the right Time events. Bluefin has a function Jobs.createJobSubscriptions which can be used to create subscriptions.
  • tokenCredential: Azure Active Directory token authentication support.
  • fullyQualifiedNamespace: The fully qualified Service Bus namespace that the connection is associated with. This is likely to be similar to {yournamespace}.servicebus.windows.net.
  • entityName: The name of the specific Service Bus entity instance under the associated Service Bus namespace.

Source code for Bluefin Jobs.createJobSubscriptions can be found here

A JobHandler must implement the interface TimeToFish.ITimerJob</br> This interface has a single method: Task<HandlerResult> Handler(TimeEvent message) The handler will be called when there is a message on the subscription and should return one of

  • HandlerResult.Success
  • HandlerResult.Failed
  • HandlerResult.Abort // used when you don´t want any retries

Example:</br> Handlers:</br> <pre><code> public class MyFirstJob : ITimerJob { public Task<HandlerResult> Handler(TimeEvent message) { Console.WriteLine($"My first job was started. {DateTime.Now}"); return Task.FromResult(HandlerResult.Success()); }

    public static (Type, string) JobDefinition { get => (typeof(MyFirstJob), "my-first-job"); }           
}

public class MySecondJob : ITimerJob
{
    public Task<HandlerResult> Handler(TimeEvent message)
    {
        Console.WriteLine($"My second job was started. {DateTime.Now}");
        return Task.FromResult(HandlerResult.Success());
    }

    public static (Type, string) JobDefinition { get => (typeof(MySecondJob), "my-second-job"); }           
}

</code></pre>

Initialization, typically in Program.cs <pre><code> await new HostBuilder() .ConfigureServices((hostContext, services) ⇒ { services.ConfigureTimerJobs(Configuration.GetConnectionString("timeTopic"), "myservice", MyFirstJob.JobDefinition, MySecondJob.JobDefinition); })
.RunConsoleAsync(); </code></pre>

or

<pre><code> await new HostBuilder() .ConfigureServices((hostContext, services) ⇒ { services.ConfigureTimerJobs(new DefaultAzureCredential(), "{yournamespace}.servicebus.windows.net", "time.events", "myservice", MyFirstJob.JobDefinition, MySecondJob.JobDefinition); })
.RunConsoleAsync(); </code></pre>

This will register the two types MyFirstJob and MySecondJob in the IoC container, wire up the two jobs with the azure servicebus and register a HostedService that will contain the messaghandlers. The code will assume that there are two subscriptions named "myservice.my-first-job" and "myservice.my-second-job" registered on the topic.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows 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
1.1.2 367 1/16/2024
1.1.1 66 1/16/2024
1.1.0 85 1/16/2024
1.0.0 449 11/24/2023
0.1.11 469 8/2/2023
0.1.10 807 12/22/2022
0.1.9 5,140 9/6/2021
0.1.6 4,981 11/4/2019
0.1.5 2,678 7/4/2019
0.1.2 613 7/4/2019