Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sharding passivate-idle-entity-after property #290

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,21 @@ public sealed class ShardOptions
/// <see cref="Akka.Cluster.Sharding.StateStoreMode.DData"/>
/// </summary>
public ShardingDDataOptions DistributedData { get; } = new();

/// <summary>
/// Set this to a time duration to have sharding passivate entities when they have not
/// received any message in this length of time. Set to <c>null</c> to disable.
/// It is always disabled if <see cref="RememberEntities"/> is enabled.
/// </summary>
// Had to do it this way because this property is a tri-state
public TimeSpan? PassivateIdleEntityAfter { get; set; } = TimeSpan.FromMinutes(2);

internal void Apply(AkkaConfigurationBuilder builder)
{
DistributedData.Apply(builder);

var sb = new StringBuilder();
sb.AppendLine("akka.cluster.sharding {");

if (Role is { })
sb.AppendLine($"role = {Role.ToHocon()}");
Expand Down Expand Up @@ -315,10 +324,10 @@ internal void Apply(AkkaConfigurationBuilder builder)
sb.AppendLine(
$"fail-on-invalid-entity-state-transition = {FailOnInvalidEntityStateTransition.ToHocon()}");

if(sb.Length == 0)
return;
// Had to do it this way because this property is a tri-state
sb.AppendLine(
$"passivate-idle-entity-after = {(PassivateIdleEntityAfter is null ? "off" : PassivateIdleEntityAfter.ToHocon())}");

sb.Insert(0, "akka.cluster.sharding {");
sb.AppendLine("}");
builder.AddHocon(sb.ToString(), HoconAddMode.Prepend);
}
Expand Down