Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Dapr.Jobs/Dapr.Jobs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<PackageId>Dapr.Jobs</PackageId>
<Title>Dapr Jobs Authoring SDK</Title>
<Description>Dapr Jobs SDK for scheduling jobs and tasks with Dapr</Description>
<VersionSuffix>alpha</VersionSuffix>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/Dapr.Jobs/DaprJobsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;
using Dapr.Common;
using Dapr.Jobs.Models;
using Dapr.Jobs.Models.Responses;
Expand All @@ -34,7 +33,6 @@ namespace Dapr.Jobs;
/// exhaustion and other problems.
/// </para>
/// </summary>
[Experimental("DAPR_JOBS", UrlFormat = "https://docs.dapr.io/developing-applications/building-blocks/jobs/jobs-overview/")]
public abstract class DaprJobsClient(Autogenerated.DaprClient client, HttpClient httpClient, string? daprApiToken = null) : IDaprClient
{
private bool disposed;
Expand Down
2 changes: 0 additions & 2 deletions src/Dapr.Jobs/DaprJobsClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;
using Dapr.Common;
using Microsoft.Extensions.Configuration;
using Autogenerated = Dapr.Client.Autogen.Grpc.v1;
Expand All @@ -22,7 +21,6 @@ namespace Dapr.Jobs;
/// Builds a <see cref="DaprJobsClient"/>.
/// </summary>
/// <param name="configuration">An optional instance of <see cref="IConfiguration"/>.</param>
[Experimental("DAPR_JOBS", UrlFormat = "https://docs.dapr.io/developing-applications/building-blocks/jobs/jobs-overview/")]
public sealed class DaprJobsClientBuilder(IConfiguration? configuration = null) : DaprGenericClientBuilder<DaprJobsClient>(configuration)
{
/// <summary>
Expand Down
10 changes: 4 additions & 6 deletions src/Dapr.Jobs/DaprJobsGrpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;
using Dapr.Common;
using Dapr.Jobs.Models;
using Dapr.Jobs.Models.Responses;
Expand All @@ -25,7 +24,6 @@ namespace Dapr.Jobs;
/// <summary>
/// A client for interacting with the Dapr endpoints.
/// </summary>
[Experimental("DAPR_JOBS", UrlFormat = "https://docs.dapr.io/developing-applications/building-blocks/jobs/jobs-overview/")]
internal sealed class DaprJobsGrpcClient(Autogenerated.Dapr.DaprClient client, HttpClient httpClient, string? daprApiToken = null) : DaprJobsClient(client, httpClient, daprApiToken: daprApiToken)
{
/// <summary>
Expand Down Expand Up @@ -134,7 +132,7 @@ public override async Task ScheduleJobAsync(string jobName, DaprJobSchedule sche

try
{
await Client.ScheduleJobAlpha1Async(envelope, grpcCallOptions).ConfigureAwait(false);
await Client.ScheduleJobAsync(envelope, grpcCallOptions).ConfigureAwait(false);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
Expand Down Expand Up @@ -169,7 +167,7 @@ public override async Task<DaprJobDetails> GetJobAsync(string jobName, Cancellat
{
var envelope = new Autogenerated.GetJobRequest { Name = jobName };
var grpcCallOptions = DaprClientUtilities.ConfigureGrpcCallOptions(typeof(DaprJobsClient).Assembly, this.DaprApiToken, cancellationToken);
var response = await Client.GetJobAlpha1Async(envelope, grpcCallOptions);
var response = await Client.GetJobAsync(envelope, grpcCallOptions);
return DeserializeJobResponse(response);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
Expand Down Expand Up @@ -228,7 +226,7 @@ internal static DaprJobDetails DeserializeJobResponse(Autogenerated.GetJobRespon
{
DueTime = !string.IsNullOrWhiteSpace(response.Job.DueTime) ? DateTime.Parse(response.Job.DueTime) : null,
Ttl = !string.IsNullOrWhiteSpace(response.Job.Ttl) ? DateTime.Parse(response.Job.Ttl) : null,
RepeatCount = (int?)response.Job.Repeats ?? 0,
RepeatCount = (int?)response.Job.Repeats,
Payload = response.Job.Data?.Value?.ToByteArray() ?? null,
FailurePolicy = failurePolicyResponse
};
Expand All @@ -251,7 +249,7 @@ public override async Task DeleteJobAsync(string jobName, CancellationToken canc
{
var envelope = new Autogenerated.DeleteJobRequest { Name = jobName };
var grpcCallOptions = DaprClientUtilities.ConfigureGrpcCallOptions(typeof(DaprJobsClient).Assembly, this.DaprApiToken, cancellationToken);
await Client.DeleteJobAlpha1Async(envelope, grpcCallOptions);
await Client.DeleteJobAsync(envelope, grpcCallOptions);
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;
using Dapr.Common.Extensions;
using Microsoft.Extensions.DependencyInjection;

Expand All @@ -20,7 +19,6 @@ namespace Dapr.Jobs.Extensions;
/// <summary>
/// Contains extension methods for using Dapr Jobs with dependency injection.
/// </summary>
[Experimental("DAPR_JOBS", UrlFormat = "https://docs.dapr.io/developing-applications/building-blocks/jobs/jobs-overview/")]
public static class DaprJobsServiceCollectionExtensions
{
/// <summary>
Expand Down
6 changes: 2 additions & 4 deletions src/Dapr.Jobs/Extensions/DaprSerializationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// limitations under the License.
// ------------------------------------------------------------------------

using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Text.Json;
using Dapr.Jobs.Models;
Expand All @@ -21,13 +20,12 @@ namespace Dapr.Jobs.Extensions;
/// <summary>
/// Provides helper extensions for performing serialization operations when scheduling one-time Cron jobs for the developer.
/// </summary>
[Experimental("DAPR_JOBS", UrlFormat = "https://docs.dapr.io/developing-applications/building-blocks/jobs/jobs-overview/")]
public static class DaprJobsSerializationExtensions
{
/// <summary>
/// Default JSON serializer options.
/// </summary>
private static readonly JsonSerializerOptions defaultOptions = new(JsonSerializerDefaults.Web);
private static readonly JsonSerializerOptions DefaultOptions = new(JsonSerializerDefaults.Web);

/// <summary>
/// Schedules a job with Dapr.
Expand All @@ -51,7 +49,7 @@ public static async Task ScheduleJobWithPayloadAsync(this DaprJobsClient client,
{
ArgumentNullException.ThrowIfNull(payload, nameof(payload));

var serializerOptions = jsonSerializerOptions ?? defaultOptions;
var serializerOptions = jsonSerializerOptions ?? DefaultOptions;
var payloadBytes =
JsonSerializer.SerializeToUtf8Bytes(payload, serializerOptions);

Expand Down
1 change: 0 additions & 1 deletion src/Dapr.Jobs/IDaprJobsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// ------------------------------------------------------------------------

using Dapr.Common;
using Microsoft.Extensions.DependencyInjection;

namespace Dapr.Jobs;

Expand Down
13 changes: 8 additions & 5 deletions src/Dapr.Jobs/Models/DaprJobSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ namespace Dapr.Jobs.Models;
/// Used to build a schedule for a job.
/// </summary>
[JsonConverter(typeof(DaprJobScheduleConverter))]
public sealed class DaprJobSchedule
public sealed partial class DaprJobSchedule
{
/// <summary>
/// A regular expression used to evaluate whether a given prefix period embodies an @every statement.
/// </summary>
private static readonly Regex isEveryExpression = new(@"^@every (\d+(m?s|m|h))+$", RegexOptions.Compiled);
private static readonly Regex IsEveryExpression = IsEveryExpressionRegex();
/// <summary>
/// The various prefixed period values allowed.
/// </summary>
private static readonly string[] acceptablePeriodValues = { "yearly", "monthly", "weekly", "daily", "midnight", "hourly" };
private static readonly string[] AcceptablePeriodValues = { "yearly", "monthly", "weekly", "daily", "midnight", "hourly" };

/// <summary>
/// The value of the expression represented by the schedule.
Expand Down Expand Up @@ -114,8 +114,8 @@ public static DaprJobSchedule FromCronExpression(CronExpressionBuilder builder)
/// </summary>
public bool IsPrefixedPeriodExpression =>
ExpressionValue.StartsWith('@') &&
(isEveryExpression.IsMatch(ExpressionValue) ||
ExpressionValue.EndsWithAny(acceptablePeriodValues, StringComparison.InvariantCulture));
(IsEveryExpression.IsMatch(ExpressionValue) ||
ExpressionValue.EndsWithAny(AcceptablePeriodValues, StringComparison.InvariantCulture));

/// <summary>
/// Reflects that the schedule represents a fixed point in time.
Expand All @@ -131,4 +131,7 @@ public static DaprJobSchedule FromCronExpression(CronExpressionBuilder builder)
/// Reflects that the schedule represents a Cron expression.
/// </summary>
public bool IsCronExpression => CronExpressionBuilder.IsCronExpression(ExpressionValue);

[GeneratedRegex(@"^@every (\d+(m?s|m|h))+$", RegexOptions.Compiled)]
private static partial Regex IsEveryExpressionRegex();
}
2 changes: 1 addition & 1 deletion src/Dapr.Protos/Protos/dapr/proto/common/v1/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@ message JobFailurePolicyConstant {
// max_retries is the optional maximum number of retries to attempt before giving up.
// If unset, the Job will be retried indefinitely.
optional uint32 max_retries = 2;
}
}
37 changes: 32 additions & 5 deletions src/Dapr.Protos/Protos/dapr/proto/runtime/v1/dapr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,45 @@ service Dapr {
// Shutdown the sidecar
rpc Shutdown (ShutdownRequest) returns (google.protobuf.Empty) {}

// Deprecated: Create and schedule a job
rpc ScheduleJobAlpha1(ScheduleJobRequest) returns (ScheduleJobResponse) {
option deprecated = true;
}

// Create and schedule a job
rpc ScheduleJobAlpha1(ScheduleJobRequest) returns (ScheduleJobResponse) {}
rpc ScheduleJob(ScheduleJobRequest) returns (ScheduleJobResponse) {}

// Deprecated: Gets a scheduled job
rpc GetJobAlpha1(GetJobRequest) returns (GetJobResponse) {
option deprecated = true;
}

// Gets a scheduled job
rpc GetJobAlpha1(GetJobRequest) returns (GetJobResponse) {}
rpc GetJob(GetJobRequest) returns (GetJobResponse) {}

// Deprecated: Delete a job
rpc DeleteJobAlpha1(DeleteJobRequest) returns (DeleteJobResponse) {
option deprecated = true;
}

// Delete a job
rpc DeleteJobAlpha1(DeleteJobRequest) returns (DeleteJobResponse) {}
rpc DeleteJob(DeleteJobRequest) returns (DeleteJobResponse) {}

// Deprecated: Delete jobs by name prefix
rpc DeleteJobsByPrefixAlpha1(DeleteJobsByPrefixRequestAlpha1) returns (DeleteJobsByPrefixResponseAlpha1) {
option deprecated = true;
}

rpc DeleteJobsByPrefixAlpha1(DeleteJobsByPrefixRequestAlpha1) returns (DeleteJobsByPrefixResponseAlpha1) {}
// Delete jobs by name prefix
rpc DeleteJobsByPrefix(DeleteJobsByPrefixRequest) returns (DeleteJobsByPrefixResponse) {}

// Deprecated: List all jobs
rpc ListJobsAlpha1(ListJobsRequestAlpha1) returns (ListJobsResponseAlpha1) {
option deprecated = true;
}

rpc ListJobsAlpha1(ListJobsRequestAlpha1) returns (ListJobsResponseAlpha1) {}
// List all jobs
rpc ListJobs(ListJobsRequest) returns (ListJobsResponse) {}

// Converse with a LLM service
rpc ConverseAlpha1(ConversationRequest) returns (ConversationResponse) {}
Expand Down
23 changes: 22 additions & 1 deletion src/Dapr.Protos/Protos/dapr/proto/runtime/v1/jobs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ message DeleteJobsByPrefixResponseAlpha1 {
// Empty
}

// DeleteJobsByPrefixRequest is the stable message to delete jobs by name prefix.
message DeleteJobsByPrefixRequest {
// name_prefix is the prefix of the job names to delete. If not provided, all
// jobs associated with this app ID will be deleted.
optional string name_prefix = 1;
}

message DeleteJobsByPrefixResponse {
// Empty
}

message ListJobsRequestAlpha1 {
// Empty
}
Expand All @@ -130,4 +141,14 @@ message ListJobsRequestAlpha1 {
message ListJobsResponseAlpha1 {
// The list of jobs.
repeated Job jobs = 1;
}
}

message ListJobsRequest {
// Empty
}

// ListJobsResponse is the stable message response containing the list of jobs.
message ListJobsResponse {
// The list of jobs.
repeated Job jobs = 1;
}
1 change: 1 addition & 0 deletions test/Dapr.Jobs.Test/Dapr.Jobs.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Dapr.Jobs\Dapr.Jobs.csproj" />
<ProjectReference Include="..\..\src\Dapr.Testcontainers.Xunit\Dapr.Testcontainers.Xunit.csproj" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions test/Dapr.Jobs.Test/DaprJobsClientBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void DaprJobsClientBuilder_ValidatesGrpcEndpointScheme()
var builder = new DaprJobsClientBuilder();
builder.UseGrpcEndpoint("ftp://example.com");

var ex = Assert.Throws<InvalidOperationException>(() => builder.Build());
var ex = Assert.Throws<InvalidOperationException>(builder.Build);
Assert.Equal("The gRPC endpoint must use http or https.", ex.Message);
}

Expand All @@ -69,7 +69,7 @@ public void DaprJobsClientBuilder_ValidatesHttpEndpointScheme()
var builder = new DaprJobsClientBuilder();
builder.UseHttpEndpoint("ftp://example.com");

var ex = Assert.Throws<InvalidOperationException>(() => builder.Build());
var ex = Assert.Throws<InvalidOperationException>(builder.Build);
Assert.Equal("The HTTP endpoint must use http or https.", ex.Message);
}

Expand Down
Loading
Loading