Simple Organized Code

Simple commands and handlers allow for clean organized code.

Commands

Commands define job arguments, and is the object that is published or scheduled. Commands should be small JSON serializable classes.

public class DoWorkCommand : IQuidjiboCommand
{
    public int Id { get; }
    public string Text { get; }
                    
    public DoWorkCommand(int id, string text)
    {
        Id = id;
        Text = text;
    }
}

Handlers

Handlers are where you compose the actual handling of the queued job. If you use DI framework integration, you can provide constructor-injected dependencies. Otherwise, leave the constructor empty.

public class DoWorkHandler : IQuidjiboHandler<DoWorkCommand>
{
    private readonly IExampleService _service;

    public DoWorkHandler()
    {
        // provide concrete dependencies when not using DI framework
        _service = new ExampleService();
    }

    public DoWorkHandler(IExampleService service)
    {
        // constructor injection using DI framework
        _service = service;
    }

    public async Task ProcessAsync(
        DoWorkCommand command, 
        IQuidjiboProgress progress, 
        CancellationToken cancellationToken)
    {
        progress.Report(1, $"Starting work for {command.Id}");

        // do work...
        await Task.Delay(25, cancellationToken);

        progress.Report(100, $"Finished work for {command.Id}");
    }
}

Configure

The builder lets you chain together your configuration. The BuildClient(), and BuildServer() methods stand up your infrastructure. Other integrations let you embed Quidjibo into your AspNet, AspNetCore, and other types of projects.

var quidjiboBuilder = new QuidjiboBuilder()
    .ConfigureLogging(loggerFactory)
    .ConfigureAssemblies(typeof(Program).GetTypeInfo().Assembly)
    .UseSqlServer("Server=localhost;Database=SampleDb;Trusted_Connection=True;")
    .ConfigurePipeline(pipeline => pipeline.UseDefault());

var client = quidjiboBuilder.BuildClient();
using (var workServer = quidjiboBuilder.BuildServer())
{
    workServer.Start();
    while(applicationIsRunning)
    {
        // keep alive in the background
    }
}