Skip to content

Commit

Permalink
Merge branch 'dev' into remove-startupdecorator
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing authored Sep 6, 2023
2 parents 2ae2e8f + deca94d commit 21176af
Show file tree
Hide file tree
Showing 48 changed files with 1,246 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
test:
- "tests/Proto.Actor.Tests/*.csproj"
- "tests/Proto.Remote.Tests/*.csproj"
- "tests/Proto.Persistence.Tests/*.csproj"
# "tests/Proto.Persistence.Tests/*.csproj"
- "tests/Proto.OpenTelemetry.Tests/*.csproj"
- "tests/Proto.Cluster.CodeGen.Tests/*.csproj"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
test:
- "tests/Proto.Actor.Tests/*.csproj"
- "tests/Proto.Remote.Tests/*.csproj"
- "tests/Proto.Persistence.Tests/*.csproj"
# "tests/Proto.Persistence.Tests/*.csproj"
- "tests/Proto.OpenTelemetry.Tests/*.csproj"
- "tests/Proto.Cluster.CodeGen.Tests/*.csproj"

Expand Down
15 changes: 15 additions & 0 deletions ProtoActor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Proto.Cluster.SeedNode.Redi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KubernetesDiagnostics", "benchmarks\KubernetesDiagnostics\KubernetesDiagnostics.csproj", "{5FECD1A8-A873-4927-81C3-E5C5A37D80C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Proto.Cluster.SeedNode.MongoDb", "src\Proto.Cluster.SeedNode.MongoDb\Proto.Cluster.SeedNode.MongoDb.csproj", "{6611DA4A-6471-45CE-A288-45BC7BF00B52}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1388,6 +1390,18 @@ Global
{5FECD1A8-A873-4927-81C3-E5C5A37D80C5}.Release|x64.Build.0 = Release|Any CPU
{5FECD1A8-A873-4927-81C3-E5C5A37D80C5}.Release|x86.ActiveCfg = Release|Any CPU
{5FECD1A8-A873-4927-81C3-E5C5A37D80C5}.Release|x86.Build.0 = Release|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Debug|x64.ActiveCfg = Debug|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Debug|x64.Build.0 = Debug|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Debug|x86.ActiveCfg = Debug|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Debug|x86.Build.0 = Debug|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Release|Any CPU.Build.0 = Release|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Release|x64.ActiveCfg = Release|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Release|x64.Build.0 = Release|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Release|x86.ActiveCfg = Release|Any CPU
{6611DA4A-6471-45CE-A288-45BC7BF00B52}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1515,6 +1529,7 @@ Global
{4DF9BBFF-C480-4550-B2BA-6603DAE6BC6F} = {3D12F5E5-9774-4D7E-8A5B-B1F64544925B}
{BDB67DAB-12F8-4D9F-BF7E-9F5D9E723816} = {3D12F5E5-9774-4D7E-8A5B-B1F64544925B}
{5FECD1A8-A873-4927-81C3-E5C5A37D80C5} = {0F3AB331-C042-4371-A2F0-0AFDFA13DC9F}
{6611DA4A-6471-45CE-A288-45BC7BF00B52} = {3D12F5E5-9774-4D7E-8A5B-B1F64544925B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CD0D1E44-8118-4682-8793-6B20ABFA824C}
Expand Down
76 changes: 76 additions & 0 deletions src/Proto.Actor/Context/StartupDeadlineContextDecorator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// -----------------------------------------------------------------------
// <copyright file="DeadlineContextDecorator.cs" company="Asynkron AB">
// Copyright (C) 2015-2022 Asynkron AB All rights reserved
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;
using Proto.Utils;

namespace Proto.Context;

[PublicAPI]
public static class StartupDeadlineContextExtensions
{
/// <summary>
/// Adds a decorator for a <see cref="ActorContext" /> that logs warning message if Receive takes more time than
/// specified timeout.
/// </summary>
/// <param name="props"></param>
/// <param name="deadline">The timeout for Receive to complete</param>
/// <param name="logger"></param>
/// <returns></returns>
public static Props WithStartupDeadlineDecorator(
this Props props,
TimeSpan deadline,
ILogger logger
) =>
props.WithContextDecorator(ctx => new StartupDeadlineContextDecorator(ctx, deadline, logger));
}

/// <summary>
/// A decorator for a <see cref="ActorContext" /> that logs warning message if Receive takes more time than specified
/// timeout.
/// </summary>
public class StartupDeadlineContextDecorator : ActorContextDecorator
{
private readonly IContext _context;
private readonly TimeSpan _deadline;
private readonly ILogger _logger;

public StartupDeadlineContextDecorator(IContext context, TimeSpan deadline, ILogger logger) : base(context)
{
_deadline = deadline;
_logger = logger;
_context = context;
}

public override async Task Receive(MessageEnvelope envelope)
{
var (m,_,_) = MessageEnvelope.Unwrap(envelope);
if (m is Started)
{
var t = base.Receive(envelope);

if (t.IsCompleted)
{
return;
}

var ok = await t.WaitUpTo(_deadline).ConfigureAwait(false);

if (!ok)
{
_logger.LogWarning("Actor {Self} deadline {Deadline}, exceeded on actor Started",
_context.Self, _deadline);

// keep waiting, we cannot just ignore and continue as an async task might still be running and updating state of the actor
// if we return here, actor concurrency guarantees could break
await t.ConfigureAwait(false);
}
}
}
}
Loading

0 comments on commit 21176af

Please sign in to comment.