Skip to content

Commit d409cb5

Browse files
committed
completing ScheudleJobAsync with schedule and no duetime
Signed-off-by: Fernando Rocha <[email protected]>
1 parent 2b272ee commit d409cb5

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

jobs/csharp/sdk/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ name: Run multi app run template
4848
expected_stdout_lines:
4949
- '== APP - job-service-sdk == Job Scheduled: R2-D2'
5050
- '== APP - job-service-sdk == Job Scheduled: C-3PO'
51-
- '== APP - job-service-sdk == Received job request...'
51+
- '== APP - job-service-sdk == Received invocation for the job R2-D2 with job data droid R2-D2'
5252
- '== APP - job-service-sdk == Starting droid: R2-D2'
5353
- '== APP - job-service-sdk == Executing maintenance job: Oil Change'
54-
- '== APP - job-service-sdk == Received job request...'
54+
- '== APP - job-service-sdk == Received trigger invocation for job name: C-3PO'
5555
- '== APP - job-service-sdk == Starting droid: C-3PO'
5656
- '== APP - job-service-sdk == Executing maintenance job: Limb Calibration'
5757
expected_stderr_lines:
@@ -77,9 +77,9 @@ The terminal console output should look similar to this, where:
7777

7878
```text
7979
== APP - job-service-sdk == Job Scheduled: R2-D2
80-
== APP - job-scheduler-sdk == Job details: {"name":"R2-D2", "dueTime":"15s", "data":{"@type":"type.googleapis.com/google.protobuf.Value", "value":{"Value":"R2-D2:Oil Change"}}}
80+
== APP - job-scheduler-sdk == Job details: {"schedule":"@every 15s","repeatCount":1,"dueTime":null,"ttl":null,"payload":"ChtkYXByLmlvL3NjaGVkdWxlL2pvYnBheWxvYWQSJXsiZHJvaWQiOiJSMi1EMiIsInRhc2siOiJPaWwgQ2hhbmdlIn0="}
8181
== APP - job-service-sdk == Job Scheduled: C-3PO
82-
== APP - job-scheduler-sdk == Job details: {"name":"C-3PO", "dueTime":"20s", "data":{"@type":"type.googleapis.com/google.protobuf.Value", "value":{"Value":"C-3PO:Limb Calibration"}}}
82+
== APP - job-scheduler-sdk == Job details: {"schedule":"@every 20s","repeatCount":1,"dueTime":null,"ttl":null,"payload":"ChtkYXByLmlvL3NjaGVkdWxlL2pvYnBheWxvYWQSK3siZHJvaWQiOiJDLTNQTyIsInRhc2siOiJMaW1iIENhbGlicmF0aW9uIn0="}
8383
== APP - job-service-sdk == Received job request...
8484
== APP - job-service-sdk == Starting droid: R2-D2
8585
== APP - job-service-sdk == Executing maintenance job: Oil Change

jobs/csharp/sdk/job-scheduler/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
var builder = WebApplication.CreateBuilder(args);
77
var app = builder.Build();
88

9+
await Task.Delay(5000); // Allow time for the job-service-sdk to start
10+
911
// Instantiate an HTTP client for invoking the job-service-sdk application
1012
var httpClient = DaprClient.CreateInvokeHttpClient(appId: "job-service-sdk");
1113

jobs/csharp/sdk/job-service/Program.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@
2626
}
2727

2828
try {
29-
//Create a Cron expression to run once after schedule defined seconds
30-
var cronBuilder = new CronExpressionBuilder().On(OnCronPeriod.Second, droidJob.DueTime);
31-
Console.WriteLine($"Scheduling job with cron expression: " + cronBuilder);
32-
3329
var jobData = new JobData {
3430
Droid = droidJob.Name,
3531
Task = droidJob.Job
3632
};
3733

38-
//await jobsClient.ScheduleJobAsync(droidJob.Name, DaprJobSchedule.FromDateTime(DateTime.UtcNow.AddSeconds(droidJob.DueTime)), JsonSerializer.SerializeToUtf8Bytes(jobData), DateTime.UtcNow, 1);
39-
await jobsClient.ScheduleJobWithPayloadAsync(droidJob.Name, DaprJobSchedule.FromCronExpression(cronBuilder), jobData, DateTime.UtcNow, 1); //Schedule cron job that repeats once
34+
await jobsClient.ScheduleJobWithPayloadAsync(droidJob.Name, DaprJobSchedule.FromDuration(TimeSpan.FromSeconds(droidJob.DueTime)), payload: jobData, repeats: 1); //Schedule cron job that repeats once
4035
Console.WriteLine($"Job Scheduled: {droidJob.Name}");
4136

4237
context.Response.StatusCode = 200;

0 commit comments

Comments
 (0)