Browse Source

Redis fixes

pull/1/head
Sebastian 9 years ago
parent
commit
c46dbf14a6
  1. 20
      src/Squidex.Infrastructure/Timers/CompletionTimer.cs
  2. 27
      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 public sealed class CompletionTimer : DisposableObject
{ {
private readonly CancellationTokenSource disposeCancellationTokenSource = new CancellationTokenSource(); private readonly CancellationTokenSource disposeToken = new CancellationTokenSource();
private readonly Task runTask; private readonly Task runTask;
private CancellationTokenSource delayCancellationSource; private CancellationTokenSource delayToken;
public CompletionTimer(int delay, Func<CancellationToken, Task> callback) 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) private async Task RunInternal(int delay, Func<CancellationToken, Task> callback)
{ {
while (!disposeCancellationTokenSource.IsCancellationRequested) while (!disposeToken.IsCancellationRequested)
{ {
try 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) catch (TaskCanceledException)
{ {
@ -51,8 +54,7 @@ namespace Squidex.Infrastructure.Timers
{ {
if (disposing) if (disposing)
{ {
delayCancellationSource?.Cancel(); disposeToken.Cancel();
disposeCancellationTokenSource.Cancel();
runTask.Wait(); runTask.Wait();
} }
@ -62,7 +64,7 @@ namespace Squidex.Infrastructure.Timers
{ {
ThrowIfDisposed(); ThrowIfDisposed();
delayCancellationSource?.Cancel(); delayToken?.Cancel();
} }
} }
} }

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

@ -6,6 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -17,7 +18,9 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.MongoDB; using Microsoft.AspNetCore.Identity.MongoDB;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Security; using Squidex.Infrastructure.Security;
using StackExchange.Redis;
namespace Squidex.Config.Identity namespace Squidex.Config.Identity
{ {
@ -27,11 +30,29 @@ namespace Squidex.Config.Identity
{ {
var dataProtection = services.AddDataProtection().SetApplicationName("Squidex"); var dataProtection = services.AddDataProtection().SetApplicationName("Squidex");
var keysFolder = configuration.GetValue<string>("squidex:identity:keysFolder"); var clustererType = configuration.GetValue<string>("squidex:clusterer:type");
if (!string.IsNullOrWhiteSpace(keysFolder)) if (clustererType.Equals("redis", StringComparison.OrdinalIgnoreCase))
{ {
dataProtection.PersistKeysToFileSystem(new DirectoryInfo(keysFolder)); 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; return services;

2
src/Squidex/appsettings.json

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

1
src/Squidex/project.json

@ -8,6 +8,7 @@
"Microsoft.AspNetCore.Authentication.Cookies": "1.1.0", "Microsoft.AspNetCore.Authentication.Cookies": "1.1.0",
"Microsoft.AspNetCore.Authentication.Google": "1.1.0", "Microsoft.AspNetCore.Authentication.Google": "1.1.0",
"Microsoft.AspNetCore.Authentication.OpenIdConnect": "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.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.HttpOverrides": "1.1.0", "Microsoft.AspNetCore.HttpOverrides": "1.1.0",
"Microsoft.AspNetCore.Identity": "1.1.0", "Microsoft.AspNetCore.Identity": "1.1.0",

Loading…
Cancel
Save