DistributedLeaseManager
2.0.0
シンプルなC#/。ネット分散リース/ロックマネージャー(DLM)の実装。
https://github.com/fbeltrao/azfunctions-distributedロックに触発されました
readmeの指示に従って、リースストレージ実装の1つをインストールします。
コントローラー/サービスの内部では、 IDistributedLeaseManagerを挿入し、 TryAcquireLeaseメソッドを呼び出します。結果が成功したかどうかを確認します - それがそうである場合、操作を続行できます。それ以外の場合、他の誰かがリースを取得しました。
await using var leaseResult = await leaseManager . TryAcquireLease ( resourceId , TimeSpan . FromSeconds ( 5 ) ) ;
if ( ! leaseResult . IsSuccessful )
{
// Someone else has required the lease for the resource.
// You may want to either retry the acqusition or abort the operation.
}
else
{
// You are the lease owner now and can safely process the resource.
// The lease will be released either when the leaseResult gets disposed
// or when the lease expires (in the example above, in 5 seconds)
} 著者が提供するものとは異なるリースストレージを使用する場合は、 DistributedLeaseManager.Coreライブラリをプロジェクトに追加し、対応するインターフェイスを実装します(既存の実装のいずれかを例として参照してください)。
パッケージにそれらを含めるために、変更を加えたPRを自由に開いてください!