ThreadService
using Skipcheck.Tm1.Client.Services; Server threads: what the server is doing right now (/Threads), and cancelling
an operation, which is how to stop a running process: cancelling a client's request
doesn't.
See what the server is busy with:
// What the server is doing now: every thread that isn't idle
return tm1
.Threads.ListAsync(
ODataQuery
.None()
.Select(Thread.Fields.Id, Thread.Fields.Name, Thread.Fields.Function, Thread.Fields.ElapsedTime)
.Filter(Thread.Fields.State.Ne("Idle"))
)
.Select(thread => $"{thread.Name}: {thread.Function} for {thread.ElapsedTime}");
Stop a running process by cancelling its thread, found by its request:
// A process run through REST shows as its request, not by its name
var running = ODataQuery
.None()
.Select(Thread.Fields.Id)
.Filter(Filter.Contains(Thread.Fields.Function, "Processes('Sales.Load')/tm1.ExecuteWithReturn"));
await foreach (var thread in tm1.Threads.ListAsync(running))
{
await tm1.Threads.CancelAsync(thread.Id!.Value);
}
Members
ThreadService constructor | A service that sends its requests through session. |
ListAsync | GET Threads, streamed. |
GetAsync | GET Threads(id), or a Tm1NotFoundException if it's gone. |
SessionAsync | GET Threads(id)/Session. |
CancelAsync | Asks the thread to stop what it's doing, such as a running process. |
ThreadService
constructorThreadService(Tm1Session session)A service that sends its requests through session.
ListAsync
IAsyncEnumerable<ServerThread> ListAsync(ODataQuery? query = null, CancellationToken cancellationToken = default)GET Threads, streamed. A process run through REST shows as its request:
Function is POST /api/v1/Processes('name')/tm1.ExecuteWithReturn, and TM1 (11.8)
leaves ObjectName empty.
TM1 REST EntitySet Threads
GetAsync
Task<ServerThread> GetAsync(long id, ODataQuery? query = null, CancellationToken cancellationToken = default)GET Threads(id), or a Tm1NotFoundException if it's gone.
TM1 REST EntitySet Threads
SessionAsync
Task<ServerSession> SessionAsync(long id, ODataQuery? query = null, CancellationToken cancellationToken = default)GET Threads(id)/Session.
TM1 REST Navigation Thread/Session
CancelAsync
Task CancelAsync(long id, CancellationToken cancellationToken = default)tm1.CancelOperation: asks the thread to stop what it's doing, such as a running
process. TM1 (11.8) then fails the process's ExecuteWithReturn request with 500,
TM1UserException: Cancel (code 174), rather than reporting it Aborted. Completes
when the request is made; the thread stops soon after. Needs schema 10.2.2.1.
TM1 REST Action Thread/CancelOperation