-
Notifications
You must be signed in to change notification settings - Fork 6
/
WhisperPolicyFactory.cs
37 lines (32 loc) · 1.19 KB
/
WhisperPolicyFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#nullable enable
using System;
using Mochineko.Relent.Resilience;
using Mochineko.Relent.Resilience.Bulkhead;
using Mochineko.Relent.Resilience.Retry;
using Mochineko.Relent.Resilience.Timeout;
using Mochineko.Relent.Resilience.Wrap;
namespace Mochineko.VoiceActivityDetection.Samples
{
internal static class WhisperPolicyFactory
{
private const float TotalTimeoutSeconds = 60f;
private const int MaxRetryCount = 10;
private const double ExponentialBackoffFactor = 0.1d;
private const double ExponentialBackoffBaseNumber = 2d;
private const int MaxParallelization = 1;
public static IPolicy<string> Build()
{
var totalTimeout = TimeoutFactory.Timeout<string>(
TimeSpan.FromSeconds(TotalTimeoutSeconds));
var retry = RetryFactory.RetryWithExponentialBackoff<string>(
MaxRetryCount,
ExponentialBackoffFactor,
ExponentialBackoffBaseNumber);
var bulkheadPolicy = BulkheadFactory.Bulkhead<string>(
MaxParallelization);
return totalTimeout
.Wrap(retry)
.Wrap(bulkheadPolicy);
}
}
}