-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
136d9f4
commit a1e6446
Showing
3 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
| ||
using Polly.Timeout; | ||
using System.Collections; | ||
|
||
namespace ConsoleTest; | ||
|
||
internal class EmpWeather | ||
{ | ||
static string url = $"http://localhost:5223/api"; | ||
static HttpClient httpClient = new HttpClient(); | ||
static string lastWeather = "this is cold from cache"; | ||
public static async Task GetWeather(params int[] empId) | ||
{ | ||
foreach (var it in empId) | ||
{ | ||
|
||
var urlLimit = $"{url}/Employee/GetWeatherForEmp/{it}"; | ||
var timeoutPolicy = | ||
Policy.TimeoutAsync( | ||
TimeSpan.FromSeconds(value: 10), | ||
TimeoutStrategy.Pessimistic, | ||
async (context, timespan, task) => | ||
{ | ||
|
||
WriteLine("timeout "); | ||
|
||
|
||
}); | ||
|
||
var dataPolicy = await timeoutPolicy | ||
.ExecuteAndCaptureAsync(async () => | ||
{ | ||
return await httpClient.GetStringAsync(urlLimit); | ||
}); | ||
|
||
if (dataPolicy.Outcome == OutcomeType.Successful) | ||
{ | ||
WriteLine($"real weather for {it} is " + dataPolicy.Result); | ||
} | ||
else | ||
{ | ||
WriteLine($"cache weather for {it} is " + lastWeather); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters