Browse Source

Redis fixes

pull/1/head
Sebastian 9 years ago
parent
commit
c46dbf14a6
  1. 20
      src/Squidex.Infrastructure/Timers/CompletionTimer.cs
  2. 21
      src/Squidex/Config/Identity/IdentityServices.cs
  3. 2
      src/Squidex/appsettings.json
  4. 1
      src/Squidex/project.json

20
src/Squidex.Infrastructure/Timers/CompletionTimer.cs

@ -16,9 +16,9 @@ namespace Squidex.Infrastructure.Timers
{
public sealed class CompletionTimer : DisposableObject
{
private readonly CancellationTokenSource disposeCancellationTokenSource = new CancellationTokenSource();
private readonly CancellationTokenSource disposeToken = new CancellationTokenSource();
private readonly Task runTask;
private CancellationTokenSource delayCancellationSource;
private CancellationTokenSource delayToken;
public CompletionTimer(int delay, Func<CancellationToken, Task> callback)
{
@ -30,15 +30,18 @@ namespace Squidex.Infrastructure.Timers
private async Task RunInternal(int delay, Func<CancellationToken, Task> callback)
{
while (!disposeCancellationTokenSource.IsCancellationRequested)
while (!disposeToken.IsCancellationRequested)
{
try
{
await callback(disposeCancellationTokenSource.Token).ConfigureAwait(false);
await callback(disposeToken.Token).ConfigureAwait(false);
delayCancellationSource = new CancellationTokenSource();
delayToken = new CancellationTokenSource();
await Task.Delay(delay, delayCancellationSource.Token).ConfigureAwait(false);
using (var cts = CancellationTokenSource.CreateLinkedTokenSource(disposeToken.Token, delayToken.Token))
{
await Task.Delay(delay, cts.Token).ConfigureAwait(false);
}
}
catch (TaskCanceledException)
{
@ -51,8 +54,7 @@ namespace Squidex.Infrastructure.Timers
{
if (disposing)
{
delayCancellationSource?.Cancel();
disposeCancellationTokenSource.Cancel();
disposeToken.Cancel();
runTask.Wait();
}
@ -62,7 +64,7 @@ namespace Squidex.Infrastructure.Timers
{
ThrowIfDisposed();
delayCancellationSource?.Cancel();
delayToken?.Cancel();
}
}
}

21
src/Squidex/Config/Identity/IdentityServices.cs

@ -6,6 +6,7 @@
// All rights reserved.
// ==========================================================================
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
@ -17,7 +18,9 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.MongoDB;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Security;
using StackExchange.Redis;
namespace Squidex.Config.Identity
{
@ -27,12 +30,30 @@ namespace Squidex.Config.Identity
{
var dataProtection = services.AddDataProtection().SetApplicationName("Squidex");
var clustererType = configuration.GetValue<string>("squidex:clusterer:type");
if (clustererType.Equals("redis", StringComparison.OrdinalIgnoreCase))
{
var connectionString = configuration.GetValue<string>("squidex:clusterer:redis:connectionString");
if (string.IsNullOrWhiteSpace(connectionString) || !Uri.IsWellFormedUriString(connectionString, UriKind.Absolute))
{
throw new ConfigurationException("You must specify the Redis connection string in the 'squidex:clusterer:redis:connectionString' configuration section.");
}
var connectionMultiplexer = ConnectionMultiplexer.Connect(connectionString);
dataProtection.PersistKeysToRedis(connectionMultiplexer);
}
else
{
var keysFolder = configuration.GetValue<string>("squidex:identity:keysFolder");
if (!string.IsNullOrWhiteSpace(keysFolder))
{
dataProtection.PersistKeysToFileSystem(new DirectoryInfo(keysFolder));
}
}
return services;
}

2
src/Squidex/appsettings.json

@ -6,7 +6,7 @@
"clusterer": {
"type": "redis",
"redis": {
"connectionString": "localhost:6379"
"connectionString": "localhost:6379,resolveDns=1"
}
},
"eventStore": {

1
src/Squidex/project.json

@ -8,6 +8,7 @@
"Microsoft.AspNetCore.Authentication.Cookies": "1.1.0",
"Microsoft.AspNetCore.Authentication.Google": "1.1.0",
"Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.1.0",
"Microsoft.AspNetCore.DataProtection.Redis": "0.1.0",
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.HttpOverrides": "1.1.0",
"Microsoft.AspNetCore.Identity": "1.1.0",

Loading…
Cancel
Save