Skip to content

Commit c99cf1b

Browse files
committed
rename scheduleconsoleapp
1 parent 0d40ae0 commit c99cf1b

File tree

7 files changed

+158
-9
lines changed

7 files changed

+158
-9
lines changed

Microsoft.DurableTask.sln

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{CECADD
8383
EndProject
8484
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared.AzureManaged.Tests", "test\Shared\AzureManaged.Tests\Shared.AzureManaged.Tests.csproj", "{3272C041-F81D-4C85-A4FB-2A700B5A7A9D}"
8585
EndProject
86-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScheduleDemo", "samples\ScheduleDemo\ScheduleDemo.csproj", "{FF37BC53-8EC1-4673-915B-E59B38E286DF}"
87-
EndProject
8886
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleAppMinimal", "samples\ConsoleAppMinimal\ConsoleAppMinimal.csproj", "{B48FACA9-A328-452A-BFAE-C4F60F9C7024}"
8987
EndProject
9088
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScheduledTasks", "src\ScheduledTasks\ScheduledTasks.csproj", "{69ED743C-D616-4530-87E2-391D249D7368}"
9189
EndProject
90+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScheduleConsoleApp", "samples\ScheduleConsoleApp\ScheduleConsoleApp.csproj", "{A89B766C-987F-4C9F-8937-D0AB9FE640C8}"
91+
EndProject
9292
Global
9393
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9494
Debug|Any CPU = Debug|Any CPU
@@ -223,10 +223,6 @@ Global
223223
{3272C041-F81D-4C85-A4FB-2A700B5A7A9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
224224
{3272C041-F81D-4C85-A4FB-2A700B5A7A9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
225225
{3272C041-F81D-4C85-A4FB-2A700B5A7A9D}.Release|Any CPU.Build.0 = Release|Any CPU
226-
{FF37BC53-8EC1-4673-915B-E59B38E286DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
227-
{FF37BC53-8EC1-4673-915B-E59B38E286DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
228-
{FF37BC53-8EC1-4673-915B-E59B38E286DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
229-
{FF37BC53-8EC1-4673-915B-E59B38E286DF}.Release|Any CPU.Build.0 = Release|Any CPU
230226
{B48FACA9-A328-452A-BFAE-C4F60F9C7024}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
231227
{B48FACA9-A328-452A-BFAE-C4F60F9C7024}.Debug|Any CPU.Build.0 = Debug|Any CPU
232228
{B48FACA9-A328-452A-BFAE-C4F60F9C7024}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -235,6 +231,10 @@ Global
235231
{69ED743C-D616-4530-87E2-391D249D7368}.Debug|Any CPU.Build.0 = Debug|Any CPU
236232
{69ED743C-D616-4530-87E2-391D249D7368}.Release|Any CPU.ActiveCfg = Release|Any CPU
237233
{69ED743C-D616-4530-87E2-391D249D7368}.Release|Any CPU.Build.0 = Release|Any CPU
234+
{A89B766C-987F-4C9F-8937-D0AB9FE640C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
235+
{A89B766C-987F-4C9F-8937-D0AB9FE640C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
236+
{A89B766C-987F-4C9F-8937-D0AB9FE640C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
237+
{A89B766C-987F-4C9F-8937-D0AB9FE640C8}.Release|Any CPU.Build.0 = Release|Any CPU
238238
EndGlobalSection
239239
GlobalSection(SolutionProperties) = preSolution
240240
HideSolutionNode = FALSE
@@ -278,6 +278,7 @@ Global
278278
{3272C041-F81D-4C85-A4FB-2A700B5A7A9D} = {CECADDB5-E30A-4CE2-8604-9AC596D4A2DC}
279279
{B48FACA9-A328-452A-BFAE-C4F60F9C7024} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17}
280280
{69ED743C-D616-4530-87E2-391D249D7368} = {8AFC9781-F6F1-4696-BB4A-9ED7CA9D612B}
281+
{A89B766C-987F-4C9F-8937-D0AB9FE640C8} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17}
281282
EndGlobalSection
282283
GlobalSection(ExtensibilityGlobals) = postSolution
283284
SolutionGuid = {AB41CB55-35EA-4986-A522-387AB3402E71}

samples/ScheduleDemo/Activities/GetStockPrice.cs renamed to samples/ScheduleConsoleApp/Activities/GetStockPrice.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using Microsoft.DurableTask;
55

6-
namespace ScheduleDemo.Activities;
6+
namespace ScheduleConsoleApp.Activities;
77

88
[DurableTask]
99
public class GetStockPrice : TaskActivity<string, decimal>

samples/ScheduleDemo/Orchestrators/StockPriceOrchestrator.cs renamed to samples/ScheduleConsoleApp/Orchestrators/StockPriceOrchestrator.cs

File renamed without changes.
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
using Microsoft.DurableTask;
4+
using Microsoft.DurableTask.Client;
5+
using Microsoft.DurableTask.Client.AzureManaged;
6+
using Microsoft.DurableTask.ScheduledTasks;
7+
using Microsoft.DurableTask.Worker;
8+
using Microsoft.DurableTask.Worker.AzureManaged;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Hosting;
11+
using Microsoft.Extensions.Logging;
12+
using ScheduleConsoleApp.Activities;
13+
14+
15+
// Create the host builder
16+
IHost host = Host.CreateDefaultBuilder(args)
17+
.ConfigureServices(services =>
18+
{
19+
string connectionString = Environment.GetEnvironmentVariable("DURABLE_TASK_SCHEDULER_CONNECTION_STRING")
20+
?? throw new InvalidOperationException("Missing required environment variable 'DURABLE_TASK_SCHEDULER_CONNECTION_STRING'");
21+
22+
// Configure the worker
23+
_ = services.AddDurableTaskWorker(builder =>
24+
{
25+
// Add the Schedule entity and demo orchestration
26+
builder.AddTasks(r =>
27+
{
28+
// Add the orchestrator class
29+
r.AddOrchestrator<StockPriceOrchestrator>();
30+
31+
// Add required activities
32+
r.AddActivity<GetStockPrice>();
33+
});
34+
35+
// Enable scheduled tasks support
36+
builder.UseDurableTaskScheduler(connectionString);
37+
builder.EnableScheduledTasksSupport();
38+
});
39+
40+
// Configure the client
41+
services.AddDurableTaskClient(builder =>
42+
{
43+
builder.UseDurableTaskScheduler(connectionString);
44+
builder.EnableScheduledTasksSupport();
45+
});
46+
47+
// Configure console logging
48+
services.AddLogging(logging =>
49+
{
50+
logging.AddSimpleConsole(options =>
51+
{
52+
options.SingleLine = true;
53+
options.UseUtcTimestamp = true;
54+
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ ";
55+
});
56+
});
57+
})
58+
.Build();
59+
60+
await host.StartAsync();
61+
62+
IScheduledTaskClient scheduledTaskClient = host.Services.GetRequiredService<IScheduledTaskClient>();
63+
64+
try
65+
{
66+
// list all schedules
67+
// Define the initial query with the desired page size
68+
ScheduleQuery query = new ScheduleQuery { PageSize = 100 };
69+
70+
// Retrieve the pageable collection of schedule IDs
71+
AsyncPageable<string> schedules = await scheduledTaskClient.ListScheduleIdsAsync(query);
72+
73+
// Initialize the continuation token
74+
string? continuationToken = null;
75+
await foreach (Page<string> page in schedules.AsPages(continuationToken))
76+
{
77+
foreach (string scheduleId in page.Values)
78+
{
79+
// Obtain the schedule handle for the current scheduleId
80+
IScheduleHandle handle = scheduledTaskClient.GetScheduleHandle(scheduleId);
81+
82+
// Delete the schedule
83+
await handle.DeleteAsync();
84+
85+
Console.WriteLine($"Deleted schedule {scheduleId}");
86+
}
87+
88+
// Update the continuation token for the next iteration
89+
continuationToken = page.ContinuationToken;
90+
91+
// If there's no continuation token, we've reached the end of the collection
92+
if (continuationToken == null)
93+
{
94+
break;
95+
}
96+
}
97+
98+
99+
// Create schedule options that runs every 4 seconds
100+
ScheduleCreationOptions scheduleOptions = new ScheduleCreationOptions("demo-schedule101", nameof(StockPriceOrchestrator), TimeSpan.FromSeconds(4))
101+
{
102+
StartAt = DateTimeOffset.UtcNow,
103+
OrchestrationInput = "MSFT"
104+
};
105+
106+
// Create the schedule and get a handle to it
107+
ScheduleHandle scheduleHandle = await scheduledTaskClient.CreateScheduleAsync(scheduleOptions);
108+
109+
// Get the schedule description
110+
ScheduleDescription scheduleDescription = await scheduleHandle.DescribeAsync();
111+
112+
// print the schedule description
113+
Console.WriteLine(scheduleDescription.ToJsonString(true));
114+
115+
Console.WriteLine("");
116+
Console.WriteLine("");
117+
Console.WriteLine("");
118+
119+
// Pause the schedule
120+
Console.WriteLine("\nPausing schedule...");
121+
await scheduleHandle.PauseAsync();
122+
scheduleDescription = await scheduleHandle.DescribeAsync();
123+
Console.WriteLine(scheduleDescription.ToJsonString(true));
124+
Console.WriteLine("");
125+
Console.WriteLine("");
126+
Console.WriteLine("");
127+
128+
129+
// Resume the schedule
130+
Console.WriteLine("\nResuming schedule...");
131+
await scheduleHandle.ResumeAsync();
132+
scheduleDescription = await scheduleHandle.DescribeAsync();
133+
Console.WriteLine(scheduleDescription.ToJsonString(true));
134+
135+
Console.WriteLine("");
136+
Console.WriteLine("");
137+
Console.WriteLine("");
138+
139+
await Task.Delay(TimeSpan.FromMinutes(30));
140+
//Console.WriteLine("\nPress any key to delete the schedule and exit...");
141+
//Console.ReadKey();
142+
}
143+
catch (Exception ex)
144+
{
145+
Console.WriteLine($"One of your schedule operations failed, please fix and rerun: {ex.Message}");
146+
}
147+
148+
await host.StopAsync();
File renamed without changes.

samples/ScheduleDemo/appsettings.json renamed to samples/ScheduleConsoleApp/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"LogLevel": {
44
"Default": "Debug",
55
"Microsoft": "Warning",
6-
"ScheduleDemo": "Debug",
6+
"ScheduleConsoleApp": "Debug",
77
"DemoOrchestration": "Debug"
88
}
99
}

samples/ScheduleDemo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Hosting;
1111
using Microsoft.Extensions.Logging;
12-
using ScheduleDemo.Activities;
12+
using ScheduleConsoleApp.Activities;
1313

1414

1515
// Create the host builder

0 commit comments

Comments
 (0)