执行包装策略时出现上述异常,包括:重试、断路器和隔板。
我有以下政策:
var sharedBulkhead = Policy.BulkheadAsync(
maxParallelization: maxParallelizations,
maxQueuingActions: maxQueuingActions,
onBulkheadRejectedAsync: (context) =>
{
Log.Info($"Bulk head rejected => Policy Wrap: {context.PolicyWrapKey}, Policy: {context.PolicyKey}, Endpoint: {context.OperationKey}");
return TaskHelper.EmptyTask;
}
);
var retryPolicy = Policy.Handle<Exception>(e => (e is HttpRequestException)).WaitAndRetryAsync(
retryCount: maxRetryCount,
sleepDurationProvider: attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)),
onRetryAsync: (exception, calculatedWaitDuration, retryCount, context) =>
{
Log.Error($"Retry => Count: {retryCount}, Wait duration: {calculatedWaitDuration}, Policy Wrap: {context.PolicyWrapKey}, Policy: {context.PolicyKey}, Endpoint: {context.OperationKey}, Exception: {exception}.");
return TaskHelper.EmptyTask;
});
var circuitBreaker = Policy.Handle<Exception>(e => (e is HttpRequestException)).CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking: maxExceptionsBeforeBreaking, …Run Code Online (Sandbox Code Playgroud) 我有以下重试策略,它使用Polly.Extensions.Http:
var retryPolicy = Policy.Handle<BrokenCircuitException>().OrTransientHttpError().WaitAndRetryAsync
(
retryCount: maxRetryCount,
sleepDurationProvider: attempt => TimeSpan.FromSeconds(Math.Pow(2, attempt)),
onRetryAsync: (exception, calculatedWaitDuration, retryCount, context) =>
{
//Code
}
);
Run Code Online (Sandbox Code Playgroud)
我想用断路器和隔板策略包装策略:
var circuitBreaker = Policy.Handle<HttpRequestException>().CircuitBreakerAsync(
exceptionsAllowedBeforeBreaking: maxExceptionsBeforeBreaking,
durationOfBreak: TimeSpan.FromSeconds(circuitBreakDurationSeconds),
onBreak: (exception, timespan, context) =>
{
//Code
},
onReset: (context) =>
{
//Code
}
);
var sharedBulkhead = Policy.BulkheadAsync(
maxParallelization: maxParallelizations,
maxQueuingActions: maxQueuingActions,
onBulkheadRejectedAsync: (context) =>
{
//Code
}
);
Run Code Online (Sandbox Code Playgroud)
我使用以下代码将策略包装在一起:
Policy.WrapAsync(retryPolicy, circuitBreaker, sharedBulkhead);
Run Code Online (Sandbox Code Playgroud)
这是一个错误: cannot convert from 'Polly.Retry.RetryPolicy<System.Net.Http.HttpResponseMessage>' to 'Polly.IAsyncPolicy'
我在使用 EF 核心批量扩展的批量插入时收到以下错误:
指数超出范围。必须为非负数且小于集合的大小。(参数“索引”)位于 System.Collections.Generic.List
1.get_Item(Int32 index) at EFCore.BulkExtensions.TableInfo.UpdateEntitiesIdentity[T](IList1 个实体,IList1 entitiesWithOutputIdentity) at EFCore.BulkExtensions.TableInfo.LoadOutputData[T](DbContext context, IList1 个实体)位于 EFCore.BulkExtensions.SqlBulkOperation.Merge[T](DbContext 上下文,IList1 entities, TableInfo tableInfo, OperationType operationType, Action1 进度)位于 EFCore.BulkExtensions.DbContextBulkExtensions.BulkInsert[T ](DbContext 上下文,IList1 entities, BulkConfig bulkConfig, Action1 进度)
位于 MyProject.Data.Repository.Repository1.CreateRange(List1 实体)
我有一个父实体和子实体。我想做的是,首先批量插入父级,然后将为父级生成的 Id 分配给其子级。然后批量插入子项。
CreateRange方法:
public List<T> CreateRange(List<T> entities)
{
var bulkConfig = new BulkConfig { PreserveInsertOrder = true, SetOutputIdentity = true };
_dbContext.BulkInsert(entities, bulkConfig);
return entities;
}
Run Code Online (Sandbox Code Playgroud)
批量插入代码:
// Index parents. (Since PreserveInsertOrder = …Run Code Online (Sandbox Code Playgroud) 我正在使用 Passport-Facebook 策略进行身份验证。请在下面找到代码:
new FacebookStrategy(
{
clientID: authConfig.facebookAuth.clientID,
clientSecret: authConfig.facebookAuth.clientSecret,
callbackURL: authConfig.facebookAuth.callbackURL,
profileURL: "https://graph.facebook.com/v2.10/me",
authorizationURL: "https://www.facebook.com/v2.10/dialog/oauth",
tokenURL: "https://graph.facebook.com/v2.10/oauth/access_token",
profileFields: ["email", "profile_pic", "gender"]
},
function(accessToken, refreshToken, profile, done) {
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误:
FacebookGraphAPIError: (#210) This call requires a Page access token.
Run Code Online (Sandbox Code Playgroud)
如何传递页面访问令牌?或者这与其他事情有关?
我在 Angular 4 中使用以下插值:
{{variable.24h_volume}}
Run Code Online (Sandbox Code Playgroud)
这会导致以下错误:
Unexpected token '0.24' at column 5 in [{{variable.24h_volume}}] in ng:///AppModule/Component.html
Run Code Online (Sandbox Code Playgroud)
这里有什么问题?
是不是以数字开头的属性名称?
我希望能够捕获并识别属于此特定类型的异常,然后返回合适的错误消息.在catch块中这样做的正确方法是什么?
我有模型 trade/ Trade .py:
from datetime import datetime
from django.db import models
from home.models import Player
class Trade(models.Model):
buyer = models.ForeignKey(Player, on_delete=models.CASCADE, related_name='buyer'),
buyee = models.ForeignKey(Player, on_delete=models.CASCADE, related_name='buyee'),
date = models.DateTimeField(default=datetime.now)
Run Code Online (Sandbox Code Playgroud)
模型主页/玩家.py:
from django.contrib.auth.models import User
from django.db import models
class Player(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True, related_name='user')
value = models.IntegerField(default=1500)
owner = models.OneToOneField(User, on_delete=models.CASCADE, related_name='owner', blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)
交易发生在 2 个Player之间。也就是说,Trade中的buyer和buyee字段是Player的外键。
现在,当我为Trade模型进行迁移时,我得到的是:
class Migration(migrations.Migration):
initial = True …Run Code Online (Sandbox Code Playgroud) c# ×4
asp.net ×3
polly ×2
angular ×1
bulkinsert ×1
django ×1
node.js ×1
passport.js ×1
python ×1