-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
36 lines (34 loc) · 1.32 KB
/
Copy pathProgram.cs
File metadata and controls
36 lines (34 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-License-Identifier: Apache-2.0
// samples/Delegate: parent agent submits a child job and emits a `delegate` event linking them.
// Spec: §10, §13.2.
using Arcp.Client;
using Arcp.Core.Leases;
using Arcp.Core.Messages;
using Arcp.Core.Transport;
using Arcp.Runtime;
var server = new ArcpServer(new ArcpServerOptions
{
Runtime = new RuntimeInfo { Name = "delegate", Version = "1.0.0" },
});
server.RegisterAgent("child", (ctx, ct) => Task.FromResult<object?>("child-done"));
server.RegisterAgent("parent", async (ctx, ct) =>
{
await ctx.DelegateAsync("child_job_001", "child", new { from = "parent" }, ct);
await ctx.LogAsync("info", "parent finished after delegating", ct);
return "parent-done";
});
var (clientT, serverT) = MemoryTransport.Pair();
_ = server.AcceptAsync(serverT);
await using var client = await ArcpClient.ConnectAsync(clientT, new ArcpClientOptions
{
Client = new ClientInfo { Name = "delegate-client", Version = "1.0.0" },
});
// Spec §9.3 deny-by-default: agent.delegate must be covered by the lease for the parent to delegate.
var lease = new Lease(new Dictionary<string, IReadOnlyList<string>>
{
["agent.delegate"] = new[] { "*" },
});
var handle = await client.SubmitAsync("parent", leaseRequest: lease);
var res = await handle.Result;
Console.WriteLine($"parent: {res.FinalStatus}");
return 0;