Easy C# API for Distributed Background Tasks/Jobs for .NET Core. Inspired by celery for python.
Clone or download
brthor Upgrade to Newtonsoft 11.0.2. Fix errors caused by introduction of Js…
…onPrimitiveConverter when deserializing exceptions (#24)
Latest commit 79bc3e4 Oct 18, 2018
Permalink
Failed to load latest commit information.
Documentation change name Oct 25, 2017
Gofer.NET.Tests Upgrade to Newtonsoft 11.0.2. Fix errors caused by introduction of Js… Oct 18, 2018
Gofer.NET.Utils Upgrade to Newtonsoft 11.0.2. Fix errors caused by introduction of Js… Oct 18, 2018
.gitignore Enhanced Task Scheduling (#10) Jan 13, 2018
.travis.yml fix version issues Nov 5, 2017
Gofer.NET.csproj Upgrade to Newtonsoft 11.0.2. Fix errors caused by introduction of Js… Oct 18, 2018
Gofer.NET.sln begin return values (#9) Nov 6, 2017
IBackendLock.cs Async redis api (#15) Sep 8, 2018
ITaskQueueBackend.cs Async redis api (#15) Sep 8, 2018
LICENSE Initial commit Oct 20, 2017
Messages.cs Utils Refactoring (#7) Nov 5, 2017
README.MD Async redis api (#15) Sep 8, 2018
RedisExtensions.cs Async redis api (#15) Sep 8, 2018
RedisLock.cs Async redis api (#15) Sep 8, 2018
RedisQueue.cs Async redis api (#15) Sep 8, 2018
RedisTaskQueueBackend.cs Async redis api (#15) Sep 8, 2018
TaskClient.cs Async redis api (#15) Sep 8, 2018
TaskQueue.cs Change Task Scheduler to enqueue jobs when they should be run accordi… Oct 12, 2018
TaskQueueBackendFactoryMethods.cs Removing Task Backups (#11) Mar 9, 2018
TaskQueueConfiguration.cs Removing Task Backups (#11) Mar 9, 2018
TaskSchedule.cs Change Task Scheduler to enqueue jobs when they should be run accordi… Oct 12, 2018
TaskScheduler.cs Change Task Scheduler to enqueue jobs when they should be run accordi… Oct 12, 2018
ThreadSafeColoredConsole.cs Async redis api (#15) Sep 8, 2018
publish.sh try glob csproj Nov 7, 2017

README.MD

Gofer.NET: Easy distributed tasks/jobs for .NET Core

Build Status Myget Version Number Join the chat at https://gitter.im/Gofer-NET/Lobby

What is this?

Run background jobs (one-off, or scheduled) on a worker pool easily.

  • Scale your worker pool by simply adding new nodes.
  • Tasks are processed at least once, and not lost if a worker dies. (Currently disabled due to incorrect behavior until further development.)
  • Supports Redis backend, with an extensible API for developing additional backends.

Inspired by celery for python, this is a distributed job runner for .NET Standard 2.0 Applications. Currently only tested using .NET Core 2.0.

Here's a quick example using the same machine to execute jobs:

    public static void Main(string[] args)
    {
        var redisConnectString = "..."

        var taskQueue = TaskQueue.Redis(redisConnectString);
        
        taskQueue.Enqueue(() => RunTask("echo"));
        taskQueue.ExecuteNext();
    }
    
    private static void RunTask(string message)
    {
        Console.WriteLine(message);
    }

Currently requires a Redis backend to function, but other backends may be developed relatively easily.

Getting Started

Get started with background jobs for your web app in 1 minute

Install the dotnet cli

We recommend using the dotnet cli, to get started, but it's not a necessity. Gofer.NET is a netstandard2.0 project, so you will need the 2.0.0 version of the dotnet cli.

$ dotnet --version
2.0.0

Create a Project

Getting started is easy. First create a new project:

dotnet new console

Add our NuGet Package to your project

Add the Gofer.NET package:

dotnet add package Gofer.NET --version 1.0.0-*

Put it all together

You can enqueue a function with any arguments that can be serialized. See examples below. Setup your Program.cs to run the task client like so:

public class Program
{
    public static void Main(string[] args)
    {
        var redisConnectString = "..."

        var taskClient = new TaskClient(TaskQueue.Redis(redisConnectString));
        
        var aStr = "astring";
        taskClient.TaskQueue.Enqueue(() => RunTaskNow(aStr));
        
        var myCustom = new CustomClass {Value="Custom!"};
        taskClient.TaskQueue.Enqueue(() => SampleAsyncFunc(myCustom));
        
        // Run a scheduled task at a defined interval
        taskClient.TaskScheduler.AddScheduledTask(() => ScheduledTask(), TimeSpan.FromSeconds(5), "scheduledTaskName");
        
        // Start the task listener, effectively turning this node into a worker.
        // At least one listener is required for scheduled or enqueued jobs to run.
        taskClient.Listen();
    }
    
    private async Task SampleAsyncFunc(object value) {
        await Task.Delay(500);
        Console.WriteLine(value.ToString());
    }
    
    private static void RunTaskNow(object value)
    {
        Console.WriteLine(value.ToString());
    }
    
    private static void ScheduledTask()
    {
        Console.WriteLine("Scheduled!");
    }
    
    private class CustomClass
    {
        public string Value { get; set; }
        
        public override string ToString()
        {
            return Value;
        }
    }
}