50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System.Text.Json;
|
|
using Tiku.Application.Jobs;
|
|
|
|
namespace Tiku.Api.Contracts;
|
|
|
|
/// <summary>
|
|
/// 创建租户后台任务请求。
|
|
/// </summary>
|
|
public sealed class CreateBackgroundJobDto
|
|
{
|
|
/// <summary>
|
|
/// 任务类型。
|
|
/// </summary>
|
|
public string JobType { get; set; } = string.Empty;
|
|
/// <summary>
|
|
/// 任务载荷。
|
|
/// </summary>
|
|
public JsonElement Payload { get; set; }
|
|
/// <summary>
|
|
/// 计划运行时间。
|
|
/// </summary>
|
|
public DateTimeOffset? RunAfter { get; set; }
|
|
/// <summary>
|
|
/// 最大重试次数。
|
|
/// </summary>
|
|
public int MaxRetries { get; set; } = 3;
|
|
/// <summary>同租户同任务类型内的可选幂等键。</summary>
|
|
public string? IdempotencyKey { get; set; }
|
|
|
|
public CreateBackgroundJobCommand ToCommand(Guid tenantId)
|
|
{
|
|
return new CreateBackgroundJobCommand(
|
|
tenantId,
|
|
JobType,
|
|
Payload.ValueKind == JsonValueKind.Undefined ? JsonSerializer.SerializeToElement(new { }) : Payload,
|
|
RunAfter,
|
|
MaxRetries,
|
|
IdempotencyKey);
|
|
}
|
|
}
|
|
|
|
/// <summary>后台任务取消请求。</summary>
|
|
public sealed class CancelBackgroundJobDto
|
|
{
|
|
/// <summary>取消原因。</summary>
|
|
[System.ComponentModel.DataAnnotations.Required]
|
|
[System.ComponentModel.DataAnnotations.StringLength(1000, MinimumLength = 3)]
|
|
public string Reason { get; set; } = string.Empty;
|
|
}
|