Skip to content

Commit

Permalink
Improve readability by renaming to 'WebServer'
Browse files Browse the repository at this point in the history
+ Rename the Elm module representing the platform interface to
'ElmWebServer' and update names in that module accordingly.
+ Move C# code for the WebServer platform into namespace 'Platform.WebServer'.
+ Change the default name for the configuration file in web server apps to 'elm-web-server.json'. Support smooth migration of projects with backward compatibility here: Support the name used before 2023 as an alternative.
+ Update some of the example apps to demo the new interface.
  • Loading branch information
Viir committed Feb 16, 2023
1 parent 3b68091 commit f0d6ce0
Show file tree
Hide file tree
Showing 25 changed files with 1,136 additions and 263 deletions.
1,065 changes: 966 additions & 99 deletions implement/elm-time/ElmTime/compile-elm-program/src/CompileBackendApp.elm

Large diffs are not rendered by default.

15 changes: 1 addition & 14 deletions implement/elm-time/ElmTime/compile-elm-program/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,7 @@ lowerSerialized argumentsJson =
defaultEntryPoints : Dict.Dict String EntryPointType
defaultEntryPoints =
CompileFullstackApp.defaultEntryPoints
|> Dict.union
(Dict.fromList
[ ( "backendMain"
, \entryPointConfig ->
CompileBackendApp.loweredForBackendApp entryPointConfig
>> Result.map
(\( compiledFiles, entryPoint ) ->
{ compiledFiles = compiledFiles
, rootModuleEntryPointKind = ClassicMakeEntryPoint entryPoint
}
)
)
]
)
|> Dict.union CompileBackendApp.entryPoints


jsonEncodeLowerForSourceFilesResponse : CompilationResponse -> Json.Encode.Value
Expand Down
10 changes: 6 additions & 4 deletions implement/elm-time/ElmTime/compile-elm-program/tests/Tests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ subscriptions _ =
}
"""
, Ok
( CompileFullstackApp.RecordElmType
{ fields = [ ( "field_name", CompileFullstackApp.LeafElmType CompileFullstackApp.IntLeaf ) ] }
, Dict.empty
)
{ stateTypeAnnotation =
CompileFullstackApp.RecordElmType
{ fields = [ ( "field_name", CompileFullstackApp.LeafElmType CompileFullstackApp.IntLeaf ) ] }
, dependencies = Dict.empty
, instantiatedConfigTypeName = [ "ElmFullstack", "BackendConfig" ]
}
)
]
|> List.map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Microsoft.Extensions.DependencyInjection;
using Pine;

namespace ElmTime.WebHost;
namespace ElmTime.Platform.WebServer;

static public class Asp
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Linq;
using Pine;

namespace ElmTime.WebHost;
namespace ElmTime.Platform.WebServer;

static public class BuildConfigurationFromArguments
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.Extensions.DependencyInjection;
using Pine;

namespace ElmTime.WebHost;
namespace ElmTime.Platform.WebServer;

static public class Configuration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace ElmTime.WebHost.InterfaceToHost;
namespace ElmTime.Platform.WebServer.InterfaceToHost;

public record AppEventStructure(
ArrivedAtTimeEventStructure? ArrivedAtTimeEvent = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
using System.Linq;
using System.Text;
using System.Text.Json;
using ElmTime.WebHost.ProcessStoreSupportingMigrations;
using ElmTime.Platform.WebServer.ProcessStoreSupportingMigrations;
using Pine;

namespace ElmTime.WebHost.PersistentProcess;
namespace ElmTime.Platform.WebServer;

public interface IPersistentProcess
{
Expand Down Expand Up @@ -195,7 +195,7 @@ static public (PersistentProcessLiveRepresentation? process, InterfaceToHost.App
compositionEventsFromLatestReduction,
overrideElmAppInterfaceConfig);

logger?.Invoke("Restored the process state in " + ((int)restoreStopwatch.Elapsed.TotalSeconds) + " seconds.");
logger?.Invoke("Restored the process state in " + (int)restoreStopwatch.Elapsed.TotalSeconds + " seconds.");

return processLiveRepresentation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Text.Json.Serialization;
using Pine;

namespace ElmTime.WebHost.ProcessStoreSupportingMigrations;
namespace ElmTime.Platform.WebServer.ProcessStoreSupportingMigrations;

public record FileStoreReaderProjectionResult(
IEnumerable<(IImmutableList<string> filePath, IReadOnlyList<byte> fileContent)> projectedFiles,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Microsoft.Extensions.Logging;
using Pine;

namespace ElmTime.WebHost;
namespace ElmTime.Platform.WebServer;

public class PublicAppState
{
Expand Down Expand Up @@ -75,7 +75,7 @@ public PublicAppState(
}

if (!lastAppEventTimeHasArrived.HasValue ||
NotifyTimeHasArrivedMaximumDistance <= (getDateTimeOffset() - lastAppEventTimeHasArrived.Value))
NotifyTimeHasArrivedMaximumDistance <= getDateTimeOffset() - lastAppEventTimeHasArrived.Value)
{
ProcessEventTimeHasArrived();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Immutable;
using System.Linq;

namespace ElmTime.WebHost;
namespace ElmTime.Platform.WebServer;

public interface IRateLimit
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using ElmTime.WebHost.ProcessStoreSupportingMigrations;
using ElmTime.Platform.WebServer.ProcessStoreSupportingMigrations;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
Expand All @@ -15,7 +15,7 @@
using Microsoft.Extensions.Logging;
using Pine;

namespace ElmTime.WebHost;
namespace ElmTime.Platform.WebServer;

public class StartupAdminInterface
{
Expand All @@ -39,9 +39,17 @@ public class StartupAdminInterface

static public string PathApiProcessHistoryFileStoreListFilesInDirectory => PathApiProcessHistoryFileStore + "/list-files-in-directory";

static public string JsonFileName => "elm-fullstack.json";
static public IImmutableList<string> JsonFilePathDefault => ImmutableList.Create("elm-web-server.json");

static public IImmutableList<string> JsonFilePath => ImmutableList.Create(JsonFileName);
static public IImmutableList<IImmutableList<string>> JsonFilePathAlternatives =
ImmutableList.Create(
JsonFilePathDefault,

/*
* Support smooth migration of projects with backwards compatibility here:
* Support the name used before 2023 as alternative.
* */
ImmutableList.Create("elm-fullstack.json"));

private readonly ILogger<StartupAdminInterface> logger;

Expand All @@ -64,7 +72,7 @@ public static void ConfigureServices(IServiceCollection services)
}

record PublicHostConfiguration(
PersistentProcess.PersistentProcessLiveRepresentation processLiveRepresentation,
PersistentProcessLiveRepresentation processLiveRepresentation,
IHost webHost);

public void Configure(
Expand Down Expand Up @@ -122,7 +130,7 @@ void startPublicApp()
logger.LogInformation("Begin to build the process live representation.");

var restoreProcessResult =
PersistentProcess.PersistentProcessLiveRepresentation.LoadFromStoreAndRestoreProcess(
PersistentProcessLiveRepresentation.LoadFromStoreAndRestoreProcess(
new ProcessStoreReaderInFileStore(processStoreFileStore),
logger: logEntry => logger.LogInformation(logEntry));

Expand Down Expand Up @@ -169,7 +177,7 @@ void maintainStoreReductions()
}

IHost buildWebHost(
PersistentProcess.ProcessAppConfig processAppConfig,
ProcessAppConfig processAppConfig,
IReadOnlyList<string> publicWebHostUrls)
{
var appConfigTree =
Expand All @@ -181,7 +189,7 @@ IHost buildWebHost(

var webAppConfigurationFile =
appConfigFilesNamesAndContents
.Where(filePathAndContent => filePathAndContent.path.SequenceEqual(JsonFilePath))
.Where(filePathAndContent => JsonFilePathAlternatives.Any(configFilePath => filePathAndContent.path.SequenceEqual(configFilePath)))
.Select(filePathAndContent => filePathAndContent.blobContent)
.Cast<ReadOnlyMemory<byte>?>()
.FirstOrDefault();
Expand Down Expand Up @@ -611,7 +619,7 @@ TruncateProcessHistoryReport truncateProcessHistory(TimeSpan productionBlockDura
var getFilesForRestoreStopwatch = System.Diagnostics.Stopwatch.StartNew();

var filesForRestore =
PersistentProcess.PersistentProcessLiveRepresentation.GetFilesForRestoreProcess(
PersistentProcessLiveRepresentation.GetFilesForRestoreProcess(
processStoreFileStore).files
.Select(filePathAndContent => filePathAndContent.Key)
.ToImmutableHashSet(EnumerableExtension.EqualityComparer<IReadOnlyList<string>>());
Expand Down Expand Up @@ -846,7 +854,7 @@ static public (int statusCode, AttemptContinueWithCompositionEventReport respons

var totalStopwatch = System.Diagnostics.Stopwatch.StartNew();

var testContinueResult = PersistentProcess.PersistentProcessLiveRepresentation.TestContinueWithCompositionEvent(
var testContinueResult = PersistentProcessLiveRepresentation.TestContinueWithCompositionEvent(
compositionLogEvent: compositionLogEvent,
fileStoreReader: processStoreFileStore,
logger: testContinueLogger);
Expand Down Expand Up @@ -890,7 +898,7 @@ static public (int statusCode, AttemptContinueWithCompositionEventReport respons
public record AttemptContinueWithCompositionEventReport(
string beginTime,
CompositionLogRecordInFile.CompositionEvent compositionEvent,
PersistentProcess.StoreProvisionalReductionReport? storeReductionReport,
StoreProvisionalReductionReport? storeReductionReport,
int? storeReductionTimeSpentMilli,
int totalTimeSpentMilli,
Result<string, string> result);
Expand All @@ -903,6 +911,6 @@ public record TruncateProcessHistoryReport(
int lockedTimeSpentMilli,
int totalTimeSpentMilli,
int storeReductionTimeSpentMilli,
PersistentProcess.StoreProvisionalReductionReport? storeReductionReport,
StoreProvisionalReductionReport? storeReductionReport,
int getFilesForRestoreTimeSpentMilli,
int deleteFilesTimeSpentMilli);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ElmTime;
namespace ElmTime.Platform.WebServer;

public record WebAppConfigurationJsonStructure(
RateLimitWindow? singleRateLimitWindowPerClientIPv4Address = null,
Expand Down
Loading

0 comments on commit f0d6ce0

Please sign in to comment.