diff --git a/examples/Jobs/JobsSample/Program.cs b/examples/Jobs/JobsSample/Program.cs index 86c1c7316..789279540 100644 --- a/examples/Jobs/JobsSample/Program.cs +++ b/examples/Jobs/JobsSample/Program.cs @@ -18,6 +18,7 @@ using Dapr.Jobs.Models; var builder = WebApplication.CreateBuilder(args); +builder.Services.AddDaprJobsClient(); builder.Logging.ClearProviders(); builder.Logging.AddConsole(); diff --git a/src/Dapr.Jobs/DaprJobsGrpcClient.cs b/src/Dapr.Jobs/DaprJobsGrpcClient.cs index 5a0216aec..d4ea9fa68 100644 --- a/src/Dapr.Jobs/DaprJobsGrpcClient.cs +++ b/src/Dapr.Jobs/DaprJobsGrpcClient.cs @@ -162,11 +162,15 @@ public override async Task 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); - return new DaprJobDetails(new DaprJobSchedule(response.Job.Schedule)) + var schedule = DateTime.TryParse(response.Job.DueTime, out var dueTime) + ? DaprJobSchedule.FromDateTime(dueTime) + : new DaprJobSchedule(response.Job.Schedule); + + return new DaprJobDetails(schedule) { - DueTime = response.Job.DueTime is not null ? DateTime.Parse(response.Job.DueTime) : null, - Ttl = response.Job.Ttl is not null ? DateTime.Parse(response.Job.Ttl) : null, - RepeatCount = response.Job.Repeats == default ? null : (int?)response.Job.Repeats, + 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, Payload = response.Job.Data.ToByteArray() }; } diff --git a/src/Dapr.Jobs/Models/DaprJobSchedule.cs b/src/Dapr.Jobs/Models/DaprJobSchedule.cs index e00c77f49..0c178a38b 100644 --- a/src/Dapr.Jobs/Models/DaprJobSchedule.cs +++ b/src/Dapr.Jobs/Models/DaprJobSchedule.cs @@ -104,7 +104,7 @@ public static DaprJobSchedule FromDuration(TimeSpan duration) /// /// Specifies a schedule in which the job is triggered weekly. /// - public static DaprJobSchedule Weekly { get; } =new DaprJobSchedule("@weekly"); + public static DaprJobSchedule Weekly { get; } = new DaprJobSchedule("@weekly"); /// /// Specifies a schedule in which the job is triggered daily.