From b4584c70841c67caf06bf4a65ed86d73d433318f Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Fri, 26 Nov 2021 11:58:43 +0100 Subject: [PATCH] Feature/webp (#798) * Webp support. * Temporary test. * Increase scripting timeouts for tests. * No quotes. --- .../Scripting/JintScriptEngine.cs | 4 ++++ .../Commands/DomainObjectGrainFormatter.cs | 4 ++-- .../Config/Domain/InfrastructureServices.cs | 15 ++++++++++++++- backend/src/Squidex/appsettings.json | 8 ++++++++ backend/tests/docker-compose.yml | 2 ++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs index 9b5056582..59be6d3f4 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs @@ -224,6 +224,10 @@ namespace Squidex.Domain.Apps.Core.Scripting { throw new ValidationException(T.Get("common.jsError", new { message = ex.Message })); } + catch (OperationCanceledException) + { + throw new ValidationException(T.Get("common.jsError", new { message = "Timeout" })); + } catch (DomainException) { throw; diff --git a/backend/src/Squidex.Infrastructure/Commands/DomainObjectGrainFormatter.cs b/backend/src/Squidex.Infrastructure/Commands/DomainObjectGrainFormatter.cs index 9cfdf1db1..239890a0b 100644 --- a/backend/src/Squidex.Infrastructure/Commands/DomainObjectGrainFormatter.cs +++ b/backend/src/Squidex.Infrastructure/Commands/DomainObjectGrainFormatter.cs @@ -11,7 +11,7 @@ namespace Squidex.Infrastructure.Commands { public static class DomainObjectGrainFormatter { - public static string Format(IIncomingGrainCallContext context) + public static readonly Func Format = context => { if (context.InterfaceMethod == null) { @@ -34,6 +34,6 @@ namespace Squidex.Infrastructure.Commands } return context.InterfaceMethod.Name; - } + }; } } diff --git a/backend/src/Squidex/Config/Domain/InfrastructureServices.cs b/backend/src/Squidex/Config/Domain/InfrastructureServices.cs index e8ca292f2..e5b6d9558 100644 --- a/backend/src/Squidex/Config/Domain/InfrastructureServices.cs +++ b/backend/src/Squidex/Config/Domain/InfrastructureServices.cs @@ -51,6 +51,19 @@ namespace Squidex.Config.Domain services.AddAsyncLocalCache(); services.AddBackgroundCache(); + var timeoutExecution = config.GetValue("scripting:timeoutExecution"); + var timeoutScript = config.GetValue("scripting:timeoutScript"); + + services.AddSingletonAs(c => + new JintScriptEngine( + c.GetRequiredService(), + c.GetRequiredService>()) + { + TimeoutExecution = timeoutExecution, + TimeoutScript = timeoutScript + + }).As(); + services.AddSingletonAs(_ => SystemClock.Instance) .As(); @@ -96,7 +109,7 @@ namespace Squidex.Config.Domain services.AddSingletonAs() .As(); - services.AddSingleton>(DomainObjectGrainFormatter.Format); + services.AddSingleton(DomainObjectGrainFormatter.Format); } public static void AddSquidexUsageTracking(this IServiceCollection services, IConfiguration config) diff --git a/backend/src/Squidex/appsettings.json b/backend/src/Squidex/appsettings.json index 62af22d7b..4d1538ab7 100644 --- a/backend/src/Squidex/appsettings.json +++ b/backend/src/Squidex/appsettings.json @@ -75,6 +75,14 @@ } }, + "scripting": { + // The timeout for the whole script execution. + "timeoutExecution": "00:00:04", + + // The timeout for the synchronous part of the script. + "timeoutScript": "00:00:00.200" + }, + "languages": { // Use custom languages where the key is the language code and the value is the english name. "custom": "" diff --git a/backend/tests/docker-compose.yml b/backend/tests/docker-compose.yml index 3b4d513d9..ff834456a 100644 --- a/backend/tests/docker-compose.yml +++ b/backend/tests/docker-compose.yml @@ -18,6 +18,8 @@ services: - IDENTITY__ADMINCLIENTSECRET=xeLd6jFxqbXJrfmNLlO2j1apagGGGSyZJhFnIuHp4I0= - STORE__MONGODB__CONFIGURATION=mongodb://mongo - STORE__TYPE=MongoDB + - SCRIPTING__TIMEOUTSCRIPT=00:00:10 + - SCRIPTING__TIMEOUTEXECUTION=00:00:10 - GRAPHQL__CACHEDURATION=0 networks: - internal