Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class ServiceCollectionExtensions
{
public static WorkflowOptions UseRedisQueues(this WorkflowOptions options, string connectionString, string prefix)
{
options.UseQueueProvider(sp => new RedisQueueProvider(connectionString, prefix, sp.GetService<ILoggerFactory>()));
options.UseQueueProvider(sp => new RedisQueueProvider(connectionString, prefix, sp.GetService<WorkflowOptions>(), sp.GetService<ILoggerFactory>()));
return options;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
using WorkflowCore.Interface;
using WorkflowCore.Models;

namespace WorkflowCore.Providers.Redis.Services
{
Expand All @@ -24,15 +25,27 @@ public class RedisQueueProvider : IQueueProvider
[QueueType.Index] = "index"
};

public RedisQueueProvider(string connectionString, string prefix, ILoggerFactory logFactory)
private readonly Dictionary<QueueType, bool> _enabledQueues = new Dictionary<QueueType, bool>
{
};

public RedisQueueProvider(string connectionString, string prefix, WorkflowOptions options, ILoggerFactory logFactory)
{
_connectionString = connectionString;
_prefix = prefix;
_enabledQueues[QueueType.Index] = options.EnableIndexes;
_enabledQueues[QueueType.Event] = options.EnableEvents;
_enabledQueues[QueueType.Workflow] = options.EnableWorkflows;
_logger = logFactory.CreateLogger(GetType());
}

public async Task QueueWork(string id, QueueType queue)
{
if (!_enabledQueues[queue])
{
return;
}

if (_redis == null)
throw new InvalidOperationException();

Expand All @@ -47,6 +60,11 @@ public async Task QueueWork(string id, QueueType queue)

public async Task<string> DequeueWork(QueueType queue, CancellationToken cancellationToken)
{
if (!_enabledQueues[queue])
{
return null;
}

if (_redis == null)
throw new InvalidOperationException();

Expand Down