Review 1.3: a request still waiting for the agent is reused, not queued again
Pressing Test forbindelsen repeatedly, or a script calling the API in a loop, added a row per call to insight.AgentRequests, each run by the agent in turn. The same pending request (kind, instance, parameters) is now returned instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
2adeef4597
commit
cade91aa4a
1 changed files with 16 additions and 4 deletions
|
|
@ -307,15 +307,27 @@ public sealed partial class InsightRepository
|
|||
return unknown;
|
||||
}
|
||||
|
||||
/// <summary>Queues a request for the agent (SQLInsight Web: INSERT only).</summary>
|
||||
/// <summary>
|
||||
/// Queues a request for the agent (SQLInsight Web: INSERT only). The same request still waiting for the agent is
|
||||
/// returned instead of a new one, so pressing the button again (or a script in a loop) does not grow the queue.
|
||||
/// </summary>
|
||||
public async Task<long> AddAgentRequestAsync(string kind, int? configuredInstanceId, string? parameters, string? by, DateTimeOffset now,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
await using var connection = await OpenAsync(cancellationToken).ConfigureAwait(false);
|
||||
return await connection.ExecuteScalarAsync<long>("""
|
||||
INSERT insight.AgentRequests (Kind, ConfiguredInstanceId, Parameters, Status, RequestedBy, RequestedAt)
|
||||
OUTPUT INSERTED.RequestId
|
||||
VALUES (@kind, @configuredInstanceId, @parameters, 'Pending', @by, @now);
|
||||
DECLARE @id bigint = (SELECT TOP (1) RequestId FROM insight.AgentRequests
|
||||
WHERE Status = 'Pending' AND Kind = @kind
|
||||
AND (ConfiguredInstanceId = @configuredInstanceId OR (@configuredInstanceId IS NULL AND ConfiguredInstanceId IS NULL))
|
||||
AND ISNULL(Parameters, N'') = ISNULL(@parameters, N'')
|
||||
ORDER BY RequestId DESC);
|
||||
IF @id IS NULL
|
||||
BEGIN
|
||||
INSERT insight.AgentRequests (Kind, ConfiguredInstanceId, Parameters, Status, RequestedBy, RequestedAt)
|
||||
VALUES (@kind, @configuredInstanceId, @parameters, 'Pending', @by, @now);
|
||||
SET @id = SCOPE_IDENTITY();
|
||||
END
|
||||
SELECT @id;
|
||||
""", new { kind, configuredInstanceId, parameters, by, now = Utc(now) }).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue