小编Nim*_*hew的帖子

Polly - 请在调用异步 ExecuteAsync(和类似)方法时使用异步定义的策略

执行包装策略时出现上述异常,包括:重试、断路器和隔板。

我有以下政策:

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)

c# asp.net polly

2
推荐指数
1
解决办法
4455
查看次数

如何在 RetryPolicy&lt;HttpResponseMessage&gt; 上使用策略包装?

我有以下重试策略,它使用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'

c# asp.net polly

2
推荐指数
1
解决办法
4294
查看次数

EF Core 批量扩展:BulkInsert 上的索引超出范围

我在使用 EF 核心批量扩展的批量插入时收到以下错误:

指数超出范围。必须为非负数且小于集合的大小。(参数“索引”)位于 System.Collections.Generic.List 1.get_Item(Int32 index) at EFCore.BulkExtensions.TableInfo.UpdateEntitiesIdentity[T](IList1 个实体,IList 1 entitiesWithOutputIdentity) at EFCore.BulkExtensions.TableInfo.LoadOutputData[T](DbContext context, IList1 个实体)位于 EFCore.BulkExtensions.SqlBulkOperation.Merge[T](DbContext 上下文,IList 1 entities, TableInfo tableInfo, OperationType operationType, Action1 进度)位于 EFCore.BulkExtensions.DbContextBulkExtensions.BulkInsert[T ](DbContext 上下文,IList 1 entities, BulkConfig bulkConfig, Action1 进度)
位于 MyProject.Data.Repository.Repository 1.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)

c# entity-framework bulkinsert entity-framework-core

2
推荐指数
1
解决办法
3235
查看次数

FacebookGraphAPIError: (#210) 此调用需要页面访问令牌

我正在使用 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)

如何传递页面访问令牌?或者这与其他事情有关?

node.js facebook-graph-api passport-facebook passport.js

1
推荐指数
1
解决办法
2906
查看次数

以数字开头的属性名称的角度插值

我在 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)

这里有什么问题?

是不是以数字开头的属性名称?

angular

1
推荐指数
1
解决办法
626
查看次数

捕获和识别HttpRequestException的正确方法是什么?"远程名称无法解析:'www.example.com'"?

我希望能够捕获并识别属于此特定类型的异常,然后返回合适的错误消息.在catch块中这样做的正确方法是什么?

c# asp.net exception-handling

1
推荐指数
1
解决办法
57
查看次数

迁移中缺少外键

我有模型 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中的buyerbuyee字段是Player的外键。

现在,当我为Trade模型进行迁移时,我得到的是:

class Migration(migrations.Migration):

    initial = True …
Run Code Online (Sandbox Code Playgroud)

python django django-models

1
推荐指数
1
解决办法
550
查看次数