File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 11#r " nuget: Markdig, 0.41.0"
2+ #r " nuget: Polly.Core, 8.5.2"
23
34open System
45open System.Net
56open System.Net .Http
7+ open System.Threading .Tasks
68open Markdig
79open System.IO
810open Markdig.Syntax
911open Markdig.Syntax .Inlines
12+ open Polly
13+ open Polly.Retry
14+ open Polly.Timeout
1015
1116let rec visitRecursively ( action : MarkdownObject -> unit ) ( node : MarkdownObject ) =
1217 match node with
@@ -33,10 +38,16 @@ let collectLinks node =
3338 urls
3439
3540let printLock = Object()
36- let checkLinkStatus ( client : HttpClient ) ( url : string ) = async {
41+ let retryPipeline =
42+ ResiliencePipelineBuilder()
43+ .AddRetry( RetryStrategyOptions())
44+ .Build()
45+ let checkLinkStatus ( client : HttpClient ) ( url : string ) = task {
3746 try
3847 lock printLock ( fun () -> printfn $" Verifying link {url}…" )
39- let! response = Async.AwaitTask <| client.GetAsync url
48+ let! response = retryPipeline.ExecuteAsync(
49+ fun _ -> ValueTask< HttpResponseMessage>( client.GetAsync url)
50+ )
4051 if response.StatusCode <> HttpStatusCode.OK then
4152 return Result.Error $" Status code {int response.StatusCode}."
4253 else
@@ -64,7 +75,7 @@ let links = collectLinks document |> Seq.filter isNonLocalLink
6475let results = Async.RunSynchronously( async {
6576 use client = new HttpClient()
6677 return ! links |> Seq.map( fun url -> async {
67- let! status = checkLinkStatus client url
78+ let! status = Async.AwaitTask <| checkLinkStatus client url
6879 return url, status
6980 }) |> Async.Parallel
7081})
You can’t perform that action at this time.
0 commit comments