feat(cli): historyread --held-marker-file for hand-paged reads
This commit is contained in:
@@ -262,6 +262,7 @@ continuation points up to `--max`. `--events` cannot be combined with `--modifie
|
||||
| `--at-time` | HistoryRead-AtTime at these comma-separated ISO 8601 UTC times; prints the status, the rows and each value's CLR type |
|
||||
| `--page-size` | Raw only: page by hand at this `NumValuesPerNode`, printing every page as `Page k: <status> values=<n> continuation=<yes\|no>[ resumed]` (a refused page is printed, never thrown) |
|
||||
| `--pause-after-page` / `--resume-when-file` / `--pause-timeout` | With `--page-size`: after page k hold the session (and its continuation point) until the file exists, then resume |
|
||||
| `--held-marker-file` | With `--page-size`: create this (empty) file when the read reaches its pause, abandon or release point |
|
||||
| `--fresh-after-failure` | With `--page-size`: after a refused resumed page, issue one fresh read of the same window (`Fresh: …`) |
|
||||
| `--abandon-after-page` | With `--page-size`: stop after page k WITHOUT releasing its continuation point — the disconnect (session close) releases it |
|
||||
| `--release-after-page` | With `--page-size`: send `releaseContinuationPoints` for page k's point and stop |
|
||||
|
||||
@@ -99,6 +99,10 @@ public class HistoryReadCommand : CommandBase
|
||||
[CommandOption("resume-when-file", Description = "With --pause-after-page: resume once this file exists (it is not read or deleted)")]
|
||||
public string? ResumeWhenFile { get; init; }
|
||||
|
||||
/// <summary>Written (empty) once the hand-paged read reaches its pause / abandon / release point, so a driver knows the page is held.</summary>
|
||||
[CommandOption("held-marker-file", Description = "With --page-size: create this file when the read reaches its pause, abandon or release point")]
|
||||
public string? HeldMarkerFile { get; init; }
|
||||
|
||||
/// <summary>How long a pause waits for <c>--resume-when-file</c> before giving up.</summary>
|
||||
[CommandOption("pause-timeout", Description = "With --pause-after-page: seconds to wait for --resume-when-file (default 300)")]
|
||||
public int PauseTimeoutSeconds { get; init; } = 300;
|
||||
@@ -203,6 +207,7 @@ public class HistoryReadCommand : CommandBase
|
||||
if (number == AbandonAfterPage)
|
||||
{
|
||||
await console.Output.WriteLineAsync($"Abandoned after page {number} (continuation not released; holding {HoldSeconds}s)");
|
||||
if (HeldMarkerFile is not null) await File.WriteAllTextAsync(HeldMarkerFile, "", ct);
|
||||
if (HoldSeconds > 0) await Task.Delay(TimeSpan.FromSeconds(HoldSeconds), ct);
|
||||
return;
|
||||
}
|
||||
@@ -210,12 +215,14 @@ public class HistoryReadCommand : CommandBase
|
||||
{
|
||||
var released = await service.HistoryReadPageAsync(details, nodeId, cp, true, ct);
|
||||
await console.Output.WriteLineAsync($"Released after page {number}: {Format(released.Status)}");
|
||||
if (HeldMarkerFile is not null) await File.WriteAllTextAsync(HeldMarkerFile, "", ct);
|
||||
if (HoldSeconds > 0) await Task.Delay(TimeSpan.FromSeconds(HoldSeconds), ct);
|
||||
return;
|
||||
}
|
||||
if (number == PauseAfterPage)
|
||||
{
|
||||
await console.Output.WriteLineAsync($"Paused after page {number}; waiting for {ResumeWhenFile}");
|
||||
if (HeldMarkerFile is not null) await File.WriteAllTextAsync(HeldMarkerFile, "", ct);
|
||||
var deadline = DateTime.UtcNow.AddSeconds(PauseTimeoutSeconds);
|
||||
while (!File.Exists(ResumeWhenFile))
|
||||
{
|
||||
|
||||
@@ -73,13 +73,16 @@ public class HistoryReadPagedCommandTests
|
||||
{
|
||||
var fake = new FakeOpcUaClientService();
|
||||
fake.HistoryPages.Enqueue(new HistoryPage(StatusCodes.Good, [Value(1, 0)], [5]));
|
||||
var held = Path.Combine(Path.GetTempPath(), "cli-held-" + Guid.NewGuid().ToString("N"));
|
||||
using var console = TestConsoleHelper.CreateConsole();
|
||||
var command = new HistoryReadCommand(new FakeOpcUaClientServiceFactory(fake))
|
||||
{
|
||||
Url = "opc.tcp://localhost:4840", NodeId = "ns=3;s=p1.x", PageSize = 1,
|
||||
AbandonAfterPage = release ? 0 : 1, ReleaseAfterPage = release ? 1 : 0,
|
||||
AbandonAfterPage = release ? 0 : 1, ReleaseAfterPage = release ? 1 : 0, HeldMarkerFile = held,
|
||||
};
|
||||
await command.ExecuteAsync(console);
|
||||
File.Exists(held).ShouldBeTrue("the held marker is written at the abandon / release point");
|
||||
File.Delete(held);
|
||||
var output = TestConsoleHelper.GetOutput(console);
|
||||
if (release)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user