Skip to content

Commit 3b76fda

Browse files
committed
IFunctionStore's Interrupt-method requires IReadOnlyList instead of IEnumerable parameter
1 parent 314c736 commit 3b76fda

File tree

13 files changed

+28
-36
lines changed

13 files changed

+28
-36
lines changed

Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/LeaseUpdaterTests/LeaseUpdaterTestFunctionStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ComplimentaryState complimentaryState
9595
public Task<bool> Interrupt(StoredId storedId, bool onlyIfExecuting)
9696
=> _inner.Interrupt(storedId, onlyIfExecuting);
9797

98-
public Task Interrupt(IEnumerable<StoredId> storedIds) => _inner.Interrupt(storedIds);
98+
public Task Interrupt(IReadOnlyList<StoredId> storedIds) => _inner.Interrupt(storedIds);
9999

100100
public Task<bool?> Interrupted(StoredId storedId) => _inner.Interrupted(storedId);
101101

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/WatchDogsTests/CrashableFunctionStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public Task<bool> Interrupt(StoredId storedId, bool onlyIfExecuting)
154154
? Task.FromException<bool>(new TimeoutException())
155155
: _inner.Interrupt(storedId, onlyIfExecuting);
156156

157-
public Task Interrupt(IEnumerable<StoredId> storedIds) => _inner.Interrupt(storedIds);
157+
public Task Interrupt(IReadOnlyList<StoredId> storedIds) => _inner.Interrupt(storedIds);
158158

159159
public Task<bool?> Interrupted(StoredId storedId)
160160
=> _crashed

Core/Cleipnir.ResilientFunctions/BaseRegistration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ public async Task<IReadOnlyList<StoredInstance>> GetInstances(Status? status = n
3636
public Task Interrupt(IEnumerable<FlowInstance> instances)
3737
=> Interrupt(instances.Select(i => i.ToStoredInstance()));
3838
public async Task Interrupt(IEnumerable<StoredInstance> storedInstances)
39-
=> await _functionStore.Interrupt(storedInstances.Select(si => new StoredId(StoredType, si)));
39+
=> await _functionStore.Interrupt(storedInstances.Select(si => new StoredId(StoredType, si)).ToList());
4040
}

Core/Cleipnir.ResilientFunctions/Storage/IFunctionStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ ComplimentaryState complimentaryState
9090
);
9191

9292
Task<bool> Interrupt(StoredId storedId, bool onlyIfExecuting);
93-
Task Interrupt(IEnumerable<StoredId> storedIds);
93+
Task Interrupt(IReadOnlyList<StoredId> storedIds);
9494
Task<bool?> Interrupted(StoredId storedId);
9595

9696
Task<StatusAndEpoch?> GetFunctionStatus(StoredId storedId);

Core/Cleipnir.ResilientFunctions/Storage/InMemoryFunctionStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public Task<bool> Interrupt(StoredId storedId, bool onlyIfExecuting)
343343
}
344344
}
345345

346-
public async Task Interrupt(IEnumerable<StoredId> storedIds)
346+
public async Task Interrupt(IReadOnlyList<StoredId> storedIds)
347347
{
348348
foreach (var storedId in storedIds)
349349
await Interrupt(storedId, onlyIfExecuting: false);

Samples/Sample.ConsoleApp/Utils/CrashableFunctionStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public Task<bool> Interrupt(StoredId storedId, bool onlyIfExecuting)
127127
? Task.FromException<bool>(new TimeoutException())
128128
: _inner.Interrupt(storedId, onlyIfExecuting);
129129

130-
public Task Interrupt(IEnumerable<StoredId> storedIds)
130+
public Task Interrupt(IReadOnlyList<StoredId> storedIds)
131131
=> _crashed
132132
? Task.FromException(new TimeoutException())
133133
: _inner.Interrupt(storedIds);

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/MariaDbFunctionStore.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,13 @@ ELSE expires
426426
return affectedRows == 1;
427427
}
428428

429-
public async Task Interrupt(IEnumerable<StoredId> storedIds)
429+
public async Task Interrupt(IReadOnlyList<StoredId> storedIds)
430430
{
431-
await using var conn = await CreateOpenConnection(_connectionString);
432-
await using var cmd = _sqlGenerator
433-
.Interrupt(storedIds)?
434-
.ToSqlCommand(conn);
435-
if (cmd == null) return;
431+
if (storedIds.Count == 0)
432+
return;
436433

434+
await using var conn = await CreateOpenConnection(_connectionString);
435+
await using var cmd = _sqlGenerator.Interrupt(storedIds).ToSqlCommand(conn);
437436
await cmd.ExecuteNonQueryAsync();
438437
}
439438

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/MariaDbMessageStore.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public async Task AppendMessages(IReadOnlyList<StoredIdAndMessage> messages, boo
112112
{
113113
if (messages.Count == 0)
114114
return;
115+
115116
var storedIds = messages.Select(m => m.StoredId).Distinct().ToList();
116117
var maxPositions = await GetMaxPositions(storedIds);
117118

@@ -124,11 +125,11 @@ public async Task AppendMessages(IReadOnlyList<StoredIdAndMessage> messages, boo
124125
).ToList();
125126

126127
var appendMessagesCommand = _sqlGenerator.AppendMessages(messagesWithPosition);
127-
var interuptsCommand = _sqlGenerator.Interrupt(storedIds);
128+
var interruptsCommand = _sqlGenerator.Interrupt(storedIds);
128129

129130
var command =
130131
interrupt
131-
? StoreCommand.Merge(appendMessagesCommand, interuptsCommand!)
132+
? StoreCommand.Merge(appendMessagesCommand, interruptsCommand)
132133
: appendMessagesCommand;
133134

134135
await using var conn = await DatabaseHelper.CreateOpenConnection(_connectionString);

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/SqlGenerator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@
55
using Cleipnir.ResilientFunctions.Messaging;
66
using Cleipnir.ResilientFunctions.Storage;
77
using Cleipnir.ResilientFunctions.Storage.Utils;
8-
using MySqlConnector;
98

109
namespace Cleipnir.ResilientFunctions.MariaDb;
1110

1211
public class SqlGenerator(string tablePrefix)
1312
{
14-
public StoreCommand? Interrupt(IEnumerable<StoredId> storedIds)
13+
public StoreCommand Interrupt(IEnumerable<StoredId> storedIds)
1514
{
1615
var conditionals = storedIds
1716
.GroupBy(id => id.Type.Value, id => id.Instance.Value)
1817
.Select(group => $"(type = {group.Key} AND instance IN ({group.Select(i => $"'{i:N}'").StringJoin(", ")}))")
1918
.StringJoin(" OR ");
20-
if (string.IsNullOrEmpty(conditionals))
21-
return null;
2219

2320
var sql = @$"
2421
UPDATE {tablePrefix}

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/PostgreSqlFunctionStore.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,12 +491,14 @@ ELSE expires
491491
return affectedRows == 1;
492492
}
493493

494-
public async Task Interrupt(IEnumerable<StoredId> storedIds)
494+
public async Task Interrupt(IReadOnlyList<StoredId> storedIds)
495495
{
496+
if (storedIds.Count == 0)
497+
return;
498+
496499
await using var conn = await CreateConnection();
497-
await using var command = _sqlGenerator.Interrupt(storedIds)?.ToNpgsqlCommand(conn);
498-
if (command != null)
499-
await command.ExecuteNonQueryAsync();
500+
await using var command = _sqlGenerator.Interrupt(storedIds).ToNpgsqlCommand(conn);
501+
await command.ExecuteNonQueryAsync();
500502
}
501503

502504
private string? _interruptedSql;

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/SqlGenerator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ namespace Cleipnir.ResilientFunctions.PostgreSQL;
1313

1414
public class SqlGenerator(string tablePrefix)
1515
{
16-
public StoreCommand? Interrupt(IEnumerable<StoredId> storedIds)
16+
public StoreCommand Interrupt(IEnumerable<StoredId> storedIds)
1717
{
1818
var conditionals = storedIds
1919
.GroupBy(id => id.Type.Value, id => id.Instance.Value)
2020
.Select(group => $"(type = {group.Key} AND instance IN ({group.Select(i => $"'{i}'").StringJoin(", ")}))")
2121
.StringJoin(" OR ");
22-
23-
if (string.IsNullOrEmpty(conditionals))
24-
return null;
2522

2623
var sql = @$"
2724
UPDATE {tablePrefix}

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlGenerator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ namespace Cleipnir.ResilientFunctions.SqlServer;
1515

1616
public class SqlGenerator(string tablePrefix)
1717
{
18-
public StoreCommand? Interrupt(IEnumerable<StoredId> storedIds)
18+
public StoreCommand Interrupt(IEnumerable<StoredId> storedIds)
1919
{
2020
var conditionals = storedIds
2121
.GroupBy(id => id.Type.Value, id => id.Instance.Value)
2222
.Select(group => $"(FlowType = {group.Key} AND FlowInstance IN ({group.Select(i => $"'{i}'").StringJoin(", ")}))")
2323
.StringJoin(" OR ");
24-
25-
if (string.IsNullOrEmpty(conditionals))
26-
return null;
2724

2825
var sql = @$"
2926
UPDATE {tablePrefix}

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlServerFunctionStore.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,13 @@ ELSE Expires
503503
return affectedRows == 1;
504504
}
505505

506-
public async Task Interrupt(IEnumerable<StoredId> storedIds)
506+
public async Task Interrupt(IReadOnlyList<StoredId> storedIds)
507507
{
508-
await using var conn = await _connFunc();
509-
await using var cmd = _sqlGenerator
510-
.Interrupt(storedIds)?
511-
.ToSqlCommand(conn);
512-
if (cmd == null) return;
508+
if (storedIds.Count == 0)
509+
return;
513510

511+
await using var conn = await _connFunc();
512+
await using var cmd = _sqlGenerator.Interrupt(storedIds).ToSqlCommand(conn);
514513
await cmd.ExecuteNonQueryAsync();
515514
}
516515

0 commit comments

Comments
 (0)