fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
570 stars 144 forks source link

Any support for cancellation tokens? #673

Open OnurGumus opened 4 years ago

OnurGumus commented 4 years ago

In the api , I am not seeing any support for cancellation. Is it possible to cancel long running queries ?

Thorium commented 4 years ago

There is timeout parameter for .GetDataContext method.

If you use Async methods, you could do your own:

module Async =
  /// Async.Start with timeout in seconds
  let StartWithTimeout (timeoutSecs:int) (computation:Async<unit>) =
    let c = new System.Threading.CancellationTokenSource(timeoutSecs*1000)
    Async.Start(computation, cancellationToken = c.Token)

...however the query will run in the end in the background. I don't know if there is database-specific commands to cancel execution. SQLProvider can commit to transactions, so cancelling a query should also roll-back the transaction.

OnurGumus commented 3 years ago

There is a DBCommand.Cancel. https://docs.microsoft.com/en-us/dotnet/api/system.data.common.dbcommand.cancel?view=net-5.0 So perhaps this could be utilized.

OnurGumus commented 3 years ago

My concern is let's say there is a DB query running potentially long, and we want to give the opportunity to cancel to the client so that the query won't be exhausting DB resources or to make sure the the query/trx is cancelled