Skip to content

Commit

Permalink
Expand state shim to inform if function application changed app state
Browse files Browse the repository at this point in the history
Some projects use this information to decide whether to persist the originating event. One example is rate-limiting in a web server application: When a client floods the server with HTTP requests when the server rejects 99% of them because of a rate-limiting scheme, it may be better not to persist these events in the event log.
  • Loading branch information
Viir committed Mar 25, 2023
1 parent dfc138b commit 8cb642d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public record JsonStateSource(JsonElement Json) : StateSource;
public record BranchStateSource(string Branch) : StateSource;
}

public record FunctionApplicationResult(Maybe<JsonElement> resultLessStateJson);
public record FunctionApplicationResult(
Maybe<JsonElement> resultLessStateJson,
bool producedStateDifferentFromStateArgument);

public record NamedExposedFunction(string functionName, ExposedFunctionDescription functionDescription);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ processEvent config hostEvent stateBefore =
Ok ( maybeFunctionResultState, maybeFunctionResultOther ) ->
let
producedStateDifferentFromStateArgument =
(maybeFunctionResultState /= Nothing)
&& (maybeFunctionResultState /= stateArgument)
updateStateResult =
case applyFunction.stateDestinationBranches of
[] ->
Expand All @@ -647,7 +651,12 @@ processEvent config hostEvent stateBefore =
Ok state ->
( state
, ApplyFunctionShimResponse (Ok { resultLessStateJson = maybeFunctionResultOther })
, ApplyFunctionShimResponse
(Ok
{ resultLessStateJson = maybeFunctionResultOther
, producedStateDifferentFromStateArgument = producedStateDifferentFromStateArgument
}
)
)
SerializeStateShimRequest stateSource ->
Expand Down Expand Up @@ -861,6 +870,7 @@ type alias ExposedFunctionDescription =
type alias FunctionApplicationResult =
{ resultLessStateJson : Maybe Json.Encode.Value
, producedStateDifferentFromStateArgument : Bool
}
"""
2 changes: 1 addition & 1 deletion implement/elm-time/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ElmTime;

public class Program
{
static public string AppVersionId => "2023-03-24";
static public string AppVersionId => "2023-03-25";

static int AdminInterfaceDefaultPort => 4000;

Expand Down
4 changes: 2 additions & 2 deletions implement/elm-time/elm-time.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>ElmTime</RootNamespace>
<AssemblyName>elm-time</AssemblyName>
<AssemblyVersion>2023.0324.0.0</AssemblyVersion>
<FileVersion>2023.0324.0.0</FileVersion>
<AssemblyVersion>2023.0325.0.0</AssemblyVersion>
<FileVersion>2023.0325.0.0</FileVersion>
<Nullable>enable</Nullable>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
Expand Down

0 comments on commit 8cb642d

Please sign in to comment.