Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Validated fix works with improved example
Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
  • Loading branch information
WhitWaldo committed Feb 26, 2025
commit af0c0d24ea1f24df27a707fe5dab31e096fdf979
9 changes: 4 additions & 5 deletions examples/Jobs/JobsSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,25 @@
var app = builder.Build();

//Set a handler to deal with incoming jobs
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(15));
app.MapDaprScheduledJobHandler(async (string jobName, ReadOnlyMemory<byte> jobPayload, ILogger? logger, CancellationToken cancellationToken) =>
{
logger?.LogInformation("Received trigger invocation for job '{jobName}'", jobName);

var deserializedPayload = Encoding.UTF8.GetString(jobPayload.Span);
logger?.LogInformation("Received invocation for the job '{jobName}' with payload '{deserializedPayload}'",
jobName, deserializedPayload);
await Task.Delay(TimeSpan.FromSeconds(3), cancellationToken);
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);

return Task.CompletedTask;
}, cancellationTokenSource.Token);
}, TimeSpan.FromSeconds(5));

using var scope = app.Services.CreateScope();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>();
var daprJobsClient = scope.ServiceProvider.GetRequiredService<DaprJobsClient>();

logger.LogInformation("Scheduling one-time job 'myJob' to execute 10 seconds from now");
await daprJobsClient.ScheduleJobAsync("myJob", DaprJobSchedule.FromDateTime(DateTime.UtcNow.AddSeconds(10)),
Encoding.UTF8.GetBytes("This is a test"));
await daprJobsClient.ScheduleJobAsync("myJob", DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(2)),
Encoding.UTF8.GetBytes("This is a test"), repeats: 10);
logger.LogInformation("Scheduled one-time job 'myJob'");

app.Run();
Expand Down