Skip to content

Commit 02f5e1c

Browse files
authored
Add sharding passivate-idle-entity-after property (#290)
1 parent 68bea48 commit 02f5e1c

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/Akka.Cluster.Hosting/AkkaClusterHostingExtensions.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,21 @@ public sealed class ShardOptions
278278
/// <see cref="Akka.Cluster.Sharding.StateStoreMode.DData"/>
279279
/// </summary>
280280
public ShardingDDataOptions DistributedData { get; } = new();
281+
282+
/// <summary>
283+
/// Set this to a time duration to have sharding passivate entities when they have not
284+
/// received any message in this length of time. Set to <c>null</c> to disable.
285+
/// It is always disabled if <see cref="RememberEntities"/> is enabled.
286+
/// </summary>
287+
// Had to do it this way because this property is a tri-state
288+
public TimeSpan? PassivateIdleEntityAfter { get; set; } = TimeSpan.FromMinutes(2);
281289

282290
internal void Apply(AkkaConfigurationBuilder builder)
283291
{
284292
DistributedData.Apply(builder);
285293

286294
var sb = new StringBuilder();
295+
sb.AppendLine("akka.cluster.sharding {");
287296

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

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

321-
sb.Insert(0, "akka.cluster.sharding {");
322331
sb.AppendLine("}");
323332
builder.AddHocon(sb.ToString(), HoconAddMode.Prepend);
324333
}

src/Akka.Hosting.API.Tests/verify/CoreApiSpec.ApproveCluster.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ namespace Akka.Cluster.Hosting
7777
public string? JournalPluginId { get; set; }
7878
public Akka.Hosting.Coordination.LeaseOptionBase? LeaseImplementation { get; set; }
7979
public System.TimeSpan? LeaseRetryInterval { get; set; }
80+
public System.TimeSpan? PassivateIdleEntityAfter { get; set; }
8081
public bool? RememberEntities { get; set; }
8182
public Akka.Cluster.Sharding.RememberEntitiesStore? RememberEntitiesStore { get; set; }
8283
public string? Role { get; set; }

0 commit comments

Comments
 (0)