Browse Source

feat(webhooks): user subscription rewrite timeout.

pull/962/head
colin 2 years ago
parent
commit
d40be0ea67
  1. 264
      aspnet-core/migrations/LY.MicroService.WebhooksManagement.EntityFrameworkCore/Migrations/20240605074803_Add-Timeout-Duration-To-Subscription.Designer.cs
  2. 28
      aspnet-core/migrations/LY.MicroService.WebhooksManagement.EntityFrameworkCore/Migrations/20240605074803_Add-Timeout-Duration-To-Subscription.cs
  3. 5
      aspnet-core/migrations/LY.MicroService.WebhooksManagement.EntityFrameworkCore/Migrations/WebhooksManagementMigrationsDbContextModelSnapshot.cs
  4. 6
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/AbpWebhooksOptions.cs
  5. 3
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/DefaultWebhookPublisher.cs
  6. 20
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/DefaultWebhookSender.cs
  7. 4
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookSenderArgs.cs
  8. 19
      aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookSubscriptionInfo.cs
  9. 7
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionCreateOrUpdateInput.cs
  10. 1
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionDto.cs
  11. 2
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionAppService.cs
  12. 2
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/Localization/Resources/en.json
  13. 2
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/Localization/Resources/zh-Hans.json
  14. 2
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionConsts.cs
  15. 1
      aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSubscription.cs

264
aspnet-core/migrations/LY.MicroService.WebhooksManagement.EntityFrameworkCore/Migrations/20240605074803_Add-Timeout-Duration-To-Subscription.Designer.cs

@ -0,0 +1,264 @@
// <auto-generated />
using System;
using LY.MicroService.WebhooksManagement.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Volo.Abp.EntityFrameworkCore;
#nullable disable
namespace LY.MicroService.WebhooksManagement.EntityFrameworkCore.Migrations
{
[DbContext(typeof(WebhooksManagementMigrationsDbContext))]
[Migration("20240605074803_Add-Timeout-Duration-To-Subscription")]
partial class AddTimeoutDurationToSubscription
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql)
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookDefinitionRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("Description")
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<string>("DisplayName")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<string>("ExtraProperties")
.HasColumnType("longtext")
.HasColumnName("ExtraProperties");
b.Property<string>("GroupName")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("varchar(128)");
b.Property<bool>("IsEnabled")
.HasColumnType("tinyint(1)");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("varchar(128)");
b.Property<string>("RequiredFeatures")
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.HasKey("Id");
b.HasIndex("GroupName");
b.HasIndex("Name")
.IsUnique();
b.ToTable("AbpWebhooksWebhooks", (string)null);
});
modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookEventRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)")
.HasColumnName("CreationTime");
b.Property<string>("Data")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("Data");
b.Property<DateTime?>("DeletionTime")
.HasColumnType("datetime(6)")
.HasColumnName("DeletionTime");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("tinyint(1)")
.HasDefaultValue(false)
.HasColumnName("IsDeleted");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<string>("WebhookName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("varchar(100)")
.HasColumnName("WebhookName");
b.HasKey("Id");
b.ToTable("AbpWebhooksEvents", (string)null);
});
modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookGroupDefinitionRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("DisplayName")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("varchar(256)");
b.Property<string>("ExtraProperties")
.HasColumnType("longtext")
.HasColumnName("ExtraProperties");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("varchar(128)");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("AbpWebhooksWebhookGroups", (string)null);
});
modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookSendRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)")
.HasColumnName("CreationTime");
b.Property<DateTime?>("LastModificationTime")
.HasColumnType("datetime(6)")
.HasColumnName("LastModificationTime");
b.Property<string>("RequestHeaders")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("RequestHeaders");
b.Property<string>("Response")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("Response");
b.Property<string>("ResponseHeaders")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("ResponseHeaders");
b.Property<int?>("ResponseStatusCode")
.HasColumnType("int");
b.Property<bool>("SendExactSameData")
.HasColumnType("tinyint(1)");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<Guid>("WebhookEventId")
.HasColumnType("char(36)");
b.Property<Guid>("WebhookSubscriptionId")
.HasColumnType("char(36)");
b.HasKey("Id");
b.HasIndex("WebhookEventId");
b.ToTable("AbpWebhooksSendAttempts", (string)null);
});
modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookSubscription", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("char(36)");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasMaxLength(40)
.HasColumnType("varchar(40)")
.HasColumnName("ConcurrencyStamp");
b.Property<DateTime>("CreationTime")
.HasColumnType("datetime(6)")
.HasColumnName("CreationTime");
b.Property<Guid?>("CreatorId")
.HasColumnType("char(36)")
.HasColumnName("CreatorId");
b.Property<string>("Description")
.HasMaxLength(128)
.HasColumnType("varchar(128)")
.HasColumnName("Description");
b.Property<string>("Headers")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("Headers");
b.Property<bool>("IsActive")
.HasColumnType("tinyint(1)");
b.Property<string>("Secret")
.HasMaxLength(128)
.HasColumnType("varchar(128)")
.HasColumnName("Secret");
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<int?>("TimeoutDuration")
.HasColumnType("int");
b.Property<string>("WebhookUri")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("varchar(255)")
.HasColumnName("WebhookUri");
b.Property<string>("Webhooks")
.HasMaxLength(2147483647)
.HasColumnType("longtext")
.HasColumnName("Webhooks");
b.HasKey("Id");
b.ToTable("AbpWebhooksSubscriptions", (string)null);
});
modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookSendRecord", b =>
{
b.HasOne("LINGYUN.Abp.WebhooksManagement.WebhookEventRecord", "WebhookEvent")
.WithOne()
.HasForeignKey("LINGYUN.Abp.WebhooksManagement.WebhookSendRecord", "WebhookEventId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("WebhookEvent");
});
#pragma warning restore 612, 618
}
}
}

28
aspnet-core/migrations/LY.MicroService.WebhooksManagement.EntityFrameworkCore/Migrations/20240605074803_Add-Timeout-Duration-To-Subscription.cs

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LY.MicroService.WebhooksManagement.EntityFrameworkCore.Migrations
{
/// <inheritdoc />
public partial class AddTimeoutDurationToSubscription : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "TimeoutDuration",
table: "AbpWebhooksSubscriptions",
type: "int",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "TimeoutDuration",
table: "AbpWebhooksSubscriptions");
}
}
}

5
aspnet-core/migrations/LY.MicroService.WebhooksManagement.EntityFrameworkCore/Migrations/WebhooksManagementMigrationsDbContextModelSnapshot.cs

@ -18,7 +18,7 @@ namespace LY.MicroService.WebhooksManagement.EntityFrameworkCore.Migrations
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.MySql)
.HasAnnotation("ProductVersion", "7.0.2")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("LINGYUN.Abp.WebhooksManagement.WebhookDefinitionRecord", b =>
@ -226,6 +226,9 @@ namespace LY.MicroService.WebhooksManagement.EntityFrameworkCore.Migrations
b.Property<Guid?>("TenantId")
.HasColumnType("char(36)");
b.Property<int?>("TimeoutDuration")
.HasColumnType("int");
b.Property<string>("WebhookUri")
.IsRequired()
.HasMaxLength(255)

6
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks.Core/LINGYUN/Abp/Webhooks/AbpWebhooksOptions.cs

@ -58,13 +58,13 @@ public class AbpWebhooksOptions
{ "X-Requested-From", "abp-webhooks" },
};
DefaultAgentIdentifier = "Abp Webhooks";
DefaultAgentIdentifier = "Abp-Webhooks";
var assembly = typeof(AbpWebhooksOptions).Assembly;
var versionAttr = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
var versionAttr = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
if (versionAttr != null)
{
DefaultAgentIdentifier += " " + versionAttr.InformationalVersion;
DefaultAgentIdentifier += "/" + versionAttr.Version;
}
}

3
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/DefaultWebhookPublisher.cs

@ -111,7 +111,8 @@ namespace LINGYUN.Abp.Webhooks
Headers = headersToSend,
Secret = webhookSubscription.Secret,
WebhookUri = webhookSubscription.WebhookUri,
SendExactSameData = sendExactSameData
SendExactSameData = sendExactSameData,
TimeoutDuration = webhookSubscription.TimeoutDuration,
});
}
}

20
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/DefaultWebhookSender.cs

@ -64,7 +64,9 @@ namespace LINGYUN.Abp.Webhooks
try
{
var response = await SendHttpRequest(request);
var client = CreateWebhookClient(webhookSenderArgs);
var response = await SendHttpRequest(client, request);
isSucceed = response.IsSuccessStatusCode;
statusCode = response.StatusCode;
@ -112,6 +114,18 @@ namespace LINGYUN.Abp.Webhooks
return new HttpRequestMessage(HttpMethod.Post, webhookSenderArgs.WebhookUri);
}
protected virtual HttpClient CreateWebhookClient(WebhookSenderArgs webhookSenderArgs)
{
var client = _httpClientFactory.CreateClient(AbpWebhooksModule.WebhooksClient);
if (webhookSenderArgs.TimeoutDuration.HasValue &&
(webhookSenderArgs.TimeoutDuration >= 10 && webhookSenderArgs.TimeoutDuration <= 300))
{
client.Timeout = TimeSpan.FromSeconds(webhookSenderArgs.TimeoutDuration.Value);
}
return client;
}
protected virtual void AddAdditionalHeaders(HttpRequestMessage request, WebhookSenderArgs webhookSenderArgs)
{
foreach (var header in _options.DefaultHttpHeaders)
@ -169,10 +183,8 @@ namespace LINGYUN.Abp.Webhooks
}
}
protected async virtual Task<HttpResponseMessage> SendHttpRequest(HttpRequestMessage request)
protected async virtual Task<HttpResponseMessage> SendHttpRequest(HttpClient client, HttpRequestMessage request)
{
var client = _httpClientFactory.CreateClient(AbpWebhooksModule.WebhooksClient);
return await client.SendAsync(request);
}

4
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookSenderArgs.cs

@ -58,6 +58,10 @@ namespace LINGYUN.Abp.Webhooks
/// </para>
/// </summary>
public bool SendExactSameData { get; set; }
/// <summary>
/// Request timeout time, in seconds
/// </summary>
public int? TimeoutDuration { get; set; }
public WebhookSenderArgs()
{

19
aspnet-core/modules/webhooks/LINGYUN.Abp.Webhooks/LINGYUN/Abp/Webhooks/WebhookSubscriptionInfo.cs

@ -28,28 +28,19 @@ namespace LINGYUN.Abp.Webhooks
/// <summary>
/// Subscribed webhook definitions unique names.It contains webhook definitions list as json
/// <para>
/// Do not change it manually.
/// Use <see cref=" WebhookSubscriptionInfoExtensions.GetSubscribedWebhooks"/>,
/// <see cref=" WebhookSubscriptionInfoExtensions.SubscribeWebhook"/>,
/// <see cref="WebhookSubscriptionInfoExtensions.UnsubscribeWebhook"/> and
/// <see cref="WebhookSubscriptionInfoExtensions.RemoveAllSubscribedWebhooks"/> to change it.
/// </para>
/// </summary>
public List<string> Webhooks { get; set; }
/// <summary>
/// Gets a set of additional HTTP headers.That headers will be sent with the webhook. It contains webhook header dictionary as json
/// <para>
/// Do not change it manually.
/// Use <see cref=" WebhookSubscriptionInfoExtensions.GetWebhookHeaders"/>,
/// <see cref="WebhookSubscriptionInfoExtensions.AddWebhookHeader"/>,
/// <see cref="WebhookSubscriptionInfoExtensions.RemoveWebhookHeader"/>,
/// <see cref="WebhookSubscriptionInfoExtensions.RemoveAllWebhookHeaders"/> to change it.
/// </para>
/// </summary>
public IDictionary<string, string> Headers { get; set; }
/// <summary>
/// Request timeout time, in seconds
/// </summary>
public int? TimeoutDuration { get; set; }
public WebhookSubscriptionInfo()
{
IsActive = true;

7
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionCreateOrUpdateInput.cs

@ -29,6 +29,13 @@ public abstract class WebhookSubscriptionCreateOrUpdateInput
[DynamicStringLength(typeof(WebhookSubscriptionConsts), nameof(WebhookSubscriptionConsts.MaxDescriptionLength))]
public string Description { get; set; }
[DynamicRange(
typeof(WebhookSubscriptionConsts),
typeof(int),
nameof(WebhookSubscriptionConsts.TimeoutDurationMinimum),
nameof(WebhookSubscriptionConsts.TimeoutDurationMaximum))]
public int? TimeoutDuration { get; set; }
public bool IsActive { get; set; }
public Guid? TenantId { get; set; }

1
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application.Contracts/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionDto.cs

@ -15,4 +15,5 @@ public class WebhookSubscriptionDto : CreationAuditedEntityDto<Guid>, IHasConcur
public List<string> Webhooks { get; set; } = new List<string>();
public IDictionary<string, string> Headers { get; set; } = new Dictionary<string, string>();
public string ConcurrencyStamp { get; set; }
public int? TimeoutDuration { get; set; }
}

2
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Application/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionAppService.cs

@ -42,6 +42,7 @@ public class WebhookSubscriptionAppService : WebhooksManagementAppServiceBase, I
{
IsActive = input.IsActive,
Description = input.Description,
TimeoutDuration = input.TimeoutDuration,
};
subscription = await SubscriptionRepository.InsertAsync(subscription);
@ -176,6 +177,7 @@ public class WebhookSubscriptionAppService : WebhooksManagementAppServiceBase, I
subscription.SetTenantId(input.TenantId);
}
subscription.IsActive = input.IsActive;
subscription.TimeoutDuration = input.TimeoutDuration;
}
private class WebhookSubscriptionGetListSpecification : Volo.Abp.Specifications.Specification<WebhookSubscription>

2
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/Localization/Resources/en.json

@ -64,6 +64,8 @@
"DisplayName:IsStatic": "Static",
"DisplayName:IsEnabled": "Enabled",
"DisplayName:RequiredFeatures": "Required Features",
"DisplayName:TimeoutDuration": "Timeout Duration(s)",
"Description:TimeoutDuration": "After setting this value, the request will be initiated using the set timeout time, Effective range 10-300s.",
"ResponseState:Successed": "Successed",
"ResponseState:Failed": "Failed",
"GroupDefinitions": "Group Definitions",

2
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/Localization/Resources/zh-Hans.json

@ -64,6 +64,8 @@
"DisplayName:IsStatic": "静态",
"DisplayName:IsEnabled": "启用",
"DisplayName:RequiredFeatures": "必要的功能",
"DisplayName:TimeoutDuration": "超时时间(s)",
"Description:TimeoutDuration": "设置此值后,将用设置的超时时间来发起请求,有效范围10-300s.",
"ResponseState:Successed": "成功",
"ResponseState:Failed": "失败",
"GroupDefinitions": "分组定义",

2
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain.Shared/LINGYUN/Abp/WebhooksManagement/WebhookSubscriptionConsts.cs

@ -7,4 +7,6 @@ public static class WebhookSubscriptionConsts
public static int MaxWebhooksLength { get; set; } = int.MaxValue;
public static int MaxHeadersLength { get; set; } = int.MaxValue;
public static int MaxDescriptionLength { get; set; } = 128;
public static int TimeoutDurationMaximum { get; set; } = 300;
public static int TimeoutDurationMinimum { get; set; } = 10;
}

1
aspnet-core/modules/webhooks/LINGYUN.Abp.WebhooksManagement.Domain/LINGYUN/Abp/WebhooksManagement/WebhookSubscription.cs

@ -17,6 +17,7 @@ public class WebhookSubscription : CreationAuditedEntity<Guid>, IHasConcurrencyS
public virtual string Headers { get; protected set; }
public virtual string Description { get; set; }
public virtual string ConcurrencyStamp { get; set; }
public virtual int? TimeoutDuration { get; set; }
protected WebhookSubscription()
{

Loading…
Cancel
Save