Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff.repanich committed Jun 12, 2017
1 parent 119881f commit c1fba2f
Show file tree
Hide file tree
Showing 27 changed files with 60 additions and 68 deletions.
29 changes: 29 additions & 0 deletions docs/Builder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The QuidjiboBuilder

## Overview
All of the components can be wired up from your favorite DI framework, but that can be a bit much. So we have a builder to help simplify the basics. The builder also allows for extension methods to be added by other integrations.

## Anatomy Of the Builder
For the most part the build is a handful of Configure methods that create the basic infrastructure. When using specific integrations such as SQL Server, or Amazon SQS, you want to tell Quidjibo about those things. Typically your use of the builder should be restricted to using the extension methods provided by the specific integration. If you are adding an integration then you most likely will be leveraging those Configure methods while building your custom extensions.

## Building A Server
The builder has a BuildServer() method that will assemble all of the configurations that you need. This method only creates and instance of the QuidjiboServer, you will need to Start(), and Stop() the server yourself. Start and stop can be done manually or if you are using aspnetcore pipeline you can tie into that process, which has a supported integration too.

## Building A Client
The client is how you queue jobs, and schedule work. Using the same builder you used for building your server you can call the BuildClient(). Building the client will create a singleton of your configured client. You can then leverage the QuidjiboClient.Instance to queue, and schedule work.

But I don't like statics it makes my code hard to test. In that case you can use IQuidjiboClient and inject that into your constructors. Checkout the DI integrations so that the client resolves correctly.

## Building Multiple Server
Each server runs a single configuration. There may be times when you need to work with multiple types of infrastructures for different parts of your application. This use case is handled by creating two or more builders, configuring them as needed, then starting, and stopping them as needed.

## Building Multiple Clients
Building muliple clients is supported too. However your static is slightly different. Using some generics we can get there but it is a little more work. First we need to create a key to diffentiate each client.

```C#
public class MyClientKey1 : IQuidjiboClientKey{}
public class MyClientKey2 : IQuidjiboClientKey{}
```

We can use these keys to create distinct clients using the BuildClient<MyClientKey1>() called on our first builder, and on the second builder BuildClient<MyClientKey2>(). Now we can use QuidjiboClient<MyClientKey1>.Instance or QuidjiboClient<MyClientKey2>.Instance. Each one is a distinct configuration. For DI we can inject IQuidjiboClient<MyClientKey1> or IQuidjiboClient<MyClientKey2> into our constructor.

2 changes: 2 additions & 0 deletions docs/CreatingJobs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Quidjibo
A task worker library for .NET with an async pipeline.
2 changes: 2 additions & 0 deletions docs/DepedencyInjection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Quidjibo
A task worker library for .NET with an async pipeline.
4 changes: 1 addition & 3 deletions src/Quidjibo.Autofac.Tests/Samples/BasicCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

namespace Quidjibo.Autofac.Tests.Samples
{
public class BasicCommand : IQuidjiboCommand
{
}
public class BasicCommand : IQuidjiboCommand { }
}
4 changes: 1 addition & 3 deletions src/Quidjibo.Autofac.Tests/Samples/SimpleJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace Quidjibo.Autofac.Tests.Samples
{
public class SimpleJob
{
public class Command : IQuidjiboCommand
{
}
public class Command : IQuidjiboCommand { }

public class Handler : IQuidjiboHandler<Command>
{
Expand Down
4 changes: 1 addition & 3 deletions src/Quidjibo.Autofac.Tests/Samples/UnhandledCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

namespace Quidjibo.Autofac.Tests.Samples
{
public class UnhandledCommand : IQuidjiboCommand
{
}
public class UnhandledCommand : IQuidjiboCommand { }
}
4 changes: 1 addition & 3 deletions src/Quidjibo.Aws.Sqs/Providers/SqsWorkProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public async Task SendAsync(WorkItem item, int delay, CancellationToken cancella

var response = await _client.SendMessageAsync(request, cancellationToken);

if (response.HttpStatusCode == HttpStatusCode.OK)
{
}
if (response.HttpStatusCode == HttpStatusCode.OK) { }
}

public async Task<List<WorkItem>> ReceiveAsync(string worker, CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

namespace Quidjibo.Azure.ServiceBus.Configurations
{
public class ServiceBusQuidjiboConfiguration: IQuidjiboConfiguration {
public class ServiceBusQuidjiboConfiguration : IQuidjiboConfiguration
{
public List<string> Queues { get; }
public bool SingleLoop { get; }
public int PollingInterval { get; }
public int MaxAttempts { get; }
public int LockInterval { get; }
public int Throttle { get; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

namespace Quidjibo.DependencyInjection.Tests.Samples
{
public class BasicCommand : IQuidjiboCommand
{
}
public class BasicCommand : IQuidjiboCommand { }
}
4 changes: 1 addition & 3 deletions src/Quidjibo.DependencyInjection.Tests/Samples/SimpleJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace Quidjibo.DependencyInjection.Tests.Samples
{
public class SimpleJob
{
public class Command : IQuidjiboCommand
{
}
public class Command : IQuidjiboCommand { }

public class Handler : IQuidjiboHandler<Command>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

namespace Quidjibo.DependencyInjection.Tests.Samples
{
public class UnhandledCommand : IQuidjiboCommand
{
}
public class UnhandledCommand : IQuidjiboCommand { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ where intf.GetTypeInfo().IsGenericType && intf.GetGenericTypeDefinition() == han
{
serviceCollection.Add(serviceDescriptor);
}

serviceCollection.Add(new ServiceDescriptor(typeof(IQuidjiboClient), _ => (IQuidjiboClient)QuidjiboClient.Instance, ServiceLifetime.Singleton));

return serviceCollection;
Expand Down
4 changes: 1 addition & 3 deletions src/Quidjibo.SimpleInjector.Tests/Samples/BasicCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

namespace Quidjibo.SimpleInjector.Tests.Samples
{
public class BasicCommand : IQuidjiboCommand
{
}
public class BasicCommand : IQuidjiboCommand { }
}
4 changes: 1 addition & 3 deletions src/Quidjibo.SimpleInjector.Tests/Samples/SimpleJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace Quidjibo.SimpleInjector.Tests.Samples
{
public class SimpleJob
{
public class Command : IQuidjiboCommand
{
}
public class Command : IQuidjiboCommand { }

public class Handler : IQuidjiboHandler<Command>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

namespace Quidjibo.SimpleInjector.Tests.Samples
{
public class UnhandledCommand : IQuidjiboCommand
{
}
public class UnhandledCommand : IQuidjiboCommand { }
}
4 changes: 1 addition & 3 deletions src/Quidjibo.StructureMap.Tests/Samples/BasicCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

namespace Quidjibo.StructureMap.Tests.Samples
{
public class BasicCommand : IQuidjiboCommand
{
}
public class BasicCommand : IQuidjiboCommand { }
}
4 changes: 1 addition & 3 deletions src/Quidjibo.StructureMap.Tests/Samples/SimpleJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ namespace Quidjibo.StructureMap.Tests.Samples
{
public class SimpleJob
{
public class Command : IQuidjiboCommand
{
}
public class Command : IQuidjiboCommand { }

public class Handler : IQuidjiboHandler<Command>
{
Expand Down
4 changes: 1 addition & 3 deletions src/Quidjibo.StructureMap.Tests/Samples/UnhandledCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

namespace Quidjibo.StructureMap.Tests.Samples
{
public class UnhandledCommand : IQuidjiboCommand
{
}
public class UnhandledCommand : IQuidjiboCommand { }
}
8 changes: 2 additions & 6 deletions src/Quidjibo.Tests/Misc/ProviderCacheKeyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@ public void When_Different_KeyType_And_Different_Name()
key2.Should().NotBe(key1);
}

public class TestClientKey1 : IQuidjiboClientKey
{
}
public class TestClientKey1 : IQuidjiboClientKey { }

public class TestClientKey2 : IQuidjiboClientKey
{
}
public class TestClientKey2 : IQuidjiboClientKey { }
}
}
4 changes: 1 addition & 3 deletions src/Quidjibo.Tests/Resolvers/ResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace Quidjibo.Tests.Resolvers
public class ResolverTests
{
[TestMethod]
public void BasicResolveTest()
{
}
public void BasicResolveTest() { }
}
}
4 changes: 1 addition & 3 deletions src/Quidjibo/Clients/IQuidjiboClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

namespace Quidjibo.Clients
{
public interface IQuidjiboClient : IQuidjiboClient<DefaultClientKey>
{
}
public interface IQuidjiboClient : IQuidjiboClient<DefaultClientKey> { }

public interface IQuidjiboClient<TKey> : IDisposable
where TKey : IQuidjiboClientKey
Expand Down
4 changes: 1 addition & 3 deletions src/Quidjibo/Commands/IQuidjiboCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace Quidjibo.Commands
{
public interface IQuidjiboCommand
{
}
public interface IQuidjiboCommand { }
}
4 changes: 1 addition & 3 deletions src/Quidjibo/Exceptions/QuidjiboNotInitializedException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace Quidjibo.Exceptions
{
public class QuidjiboNotInitializedException : Exception
{
public QuidjiboNotInitializedException() : base("The QuidjiboClient has not been initialized. This could be a timing issue or the BuildClient method was not invoked.")
{
}
public QuidjiboNotInitializedException() : base("The QuidjiboClient has not been initialized. This could be a timing issue or the BuildClient method was not invoked.") { }
}
}
4 changes: 1 addition & 3 deletions src/Quidjibo/Misc/DefaultClientKey.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace Quidjibo.Misc
{
public class DefaultClientKey : IQuidjiboClientKey
{
}
public class DefaultClientKey : IQuidjiboClientKey { }
}
4 changes: 1 addition & 3 deletions src/Quidjibo/Misc/IQuidjiboClientKey.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
namespace Quidjibo.Misc
{
public interface IQuidjiboClientKey
{
}
public interface IQuidjiboClientKey { }
}
1 change: 1 addition & 0 deletions src/Quidjibo/QuidjiboBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private void BackFillDefaults()
{
return;
}

_cronProvider = _cronProvider ?? new CronProvider();
_dispatcher = _dispatcher ?? new WorkDispatcher(new PayloadResolver());
_loggerFactory = _loggerFactory ?? new LoggerFactory();
Expand Down
4 changes: 1 addition & 3 deletions src/Quidjibo/Resolvers/PayloadResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ where info.IsAssignableFrom(t.GetTypeInfo())
return Activator.CreateInstance(type);
}

public void Dispose()
{
}
public void Dispose() { }

public IDisposable Begin()
{
Expand Down

0 comments on commit c1fba2f

Please sign in to comment.