Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Schedule Support #368

Open
wants to merge 208 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
dec3aee
update sln
YunchuWang Jan 21, 2025
7234933
save
YunchuWang Jan 22, 2025
c95b539
save
YunchuWang Jan 24, 2025
538581b
save
YunchuWang Jan 26, 2025
a65c5e8
save
YunchuWang Jan 26, 2025
ea5e733
save
YunchuWang Jan 26, 2025
4be057e
save
YunchuWang Jan 26, 2025
92923bf
save
YunchuWang Jan 26, 2025
29235d7
save
YunchuWang Jan 26, 2025
e4759f2
save
YunchuWang Jan 26, 2025
c5e1be3
save
YunchuWang Jan 26, 2025
e90687e
save
YunchuWang Jan 26, 2025
2ee50e1
save
YunchuWang Jan 26, 2025
a4572c3
Merge branch 'main' of https://github.com/microsoft/durabletask-dotne…
YunchuWang Feb 18, 2025
a1c9be8
save
YunchuWang Feb 19, 2025
208f35d
save
YunchuWang Feb 19, 2025
2b19037
save
YunchuWang Feb 19, 2025
2e126b3
save
YunchuWang Feb 19, 2025
6cab35c
save
YunchuWang Feb 19, 2025
2b983b3
save
YunchuWang Feb 19, 2025
4ffd60a
save
YunchuWang Feb 19, 2025
6741e6d
save
YunchuWang Feb 19, 2025
93ee632
save
YunchuWang Feb 19, 2025
9987b15
save
YunchuWang Feb 19, 2025
6a75677
save
YunchuWang Feb 19, 2025
7024f00
add
YunchuWang Feb 19, 2025
4c1036c
save
YunchuWang Feb 19, 2025
08c0f5c
save
YunchuWang Feb 19, 2025
a6951bf
save
YunchuWang Feb 19, 2025
1e968d1
save
YunchuWang Feb 19, 2025
a93af82
save
YunchuWang Feb 19, 2025
588da82
save
YunchuWang Feb 19, 2025
37b4f47
save
YunchuWang Feb 19, 2025
6bdbc58
save
YunchuWang Feb 19, 2025
2f0e099
save
YunchuWang Feb 19, 2025
4ef7640
save
YunchuWang Feb 19, 2025
c6ca883
save
YunchuWang Feb 19, 2025
878e658
save
YunchuWang Feb 20, 2025
d14c484
save
YunchuWang Feb 20, 2025
ac7cd58
save
YunchuWang Feb 20, 2025
53d7193
save
YunchuWang Feb 20, 2025
3d832d3
save
YunchuWang Feb 20, 2025
baf0a51
save
YunchuWang Feb 20, 2025
3879329
save
YunchuWang Feb 20, 2025
bf2ece5
save
YunchuWang Feb 20, 2025
30a843e
SAVE
YunchuWang Feb 20, 2025
8093ac0
save
YunchuWang Feb 20, 2025
3a833df
save
YunchuWang Feb 20, 2025
7c0d7af
save
YunchuWang Feb 20, 2025
5f7c168
save
YunchuWang Feb 20, 2025
88e6f77
save
YunchuWang Feb 20, 2025
dd5f9e4
save
YunchuWang Feb 20, 2025
436850e
save
YunchuWang Feb 20, 2025
d4eb72f
save
YunchuWang Feb 20, 2025
b970487
Merge branch 'main' into wangbill/update-sln
YunchuWang Feb 20, 2025
66dfaf4
save
YunchuWang Feb 20, 2025
78dc92d
save
YunchuWang Feb 20, 2025
c16fd50
save
YunchuWang Feb 20, 2025
a10cd16
save
YunchuWang Feb 20, 2025
c39d8f2
save
YunchuWang Feb 20, 2025
e99de8c
save
YunchuWang Feb 20, 2025
eefa761
save
YunchuWang Feb 20, 2025
6a2ea18
save
YunchuWang Feb 20, 2025
c5daf43
save
YunchuWang Feb 20, 2025
6f19602
save
YunchuWang Feb 20, 2025
4dce0b0
save
YunchuWang Feb 21, 2025
bec67a1
save
YunchuWang Feb 21, 2025
8d28be4
save
YunchuWang Feb 21, 2025
07a7c0d
save
YunchuWang Feb 21, 2025
5d556ad
save
YunchuWang Feb 21, 2025
8eb0f4b
save
YunchuWang Feb 21, 2025
6812fb1
save
YunchuWang Feb 21, 2025
cc130f2
save
YunchuWang Feb 21, 2025
6a46b3a
save
YunchuWang Feb 21, 2025
9e9fb6a
save
YunchuWang Feb 21, 2025
1fb1149
save
YunchuWang Feb 21, 2025
6ab593b
save
YunchuWang Feb 21, 2025
eb9853d
save
YunchuWang Feb 21, 2025
beb40cf
save
YunchuWang Feb 21, 2025
1879dcd
save
YunchuWang Feb 21, 2025
4985b04
save
YunchuWang Feb 21, 2025
28bebd5
save
YunchuWang Feb 21, 2025
067bb19
save
YunchuWang Feb 21, 2025
c3c6ed0
save
YunchuWang Feb 21, 2025
2dbf58a
save
YunchuWang Feb 21, 2025
d6dae32
save
YunchuWang Feb 21, 2025
41603fe
save
YunchuWang Feb 21, 2025
00f5660
fix
YunchuWang Feb 21, 2025
53c7518
cleanup
YunchuWang Feb 21, 2025
fde15ac
demo1
YunchuWang Feb 21, 2025
d060215
take orch inst id from creationoptions if provided
YunchuWang Feb 21, 2025
d961973
save
YunchuWang Feb 21, 2025
556e8f4
remove unsupported for now
YunchuWang Feb 21, 2025
51cc78a
save
YunchuWang Feb 21, 2025
fb31819
save
YunchuWang Feb 21, 2025
f580034
save
YunchuWang Feb 21, 2025
4bebb19
comment
YunchuWang Feb 21, 2025
7bffc26
save
YunchuWang Feb 21, 2025
e13b25d
style
YunchuWang Feb 21, 2025
9048e15
update eventids
YunchuWang Feb 21, 2025
8200072
startimmediatelyifalte
YunchuWang Feb 21, 2025
0f88a0b
save
YunchuWang Feb 21, 2025
75fb8e3
refactor
YunchuWang Feb 21, 2025
56d9443
save
YunchuWang Feb 21, 2025
e16ab9c
before waiter refactor
YunchuWang Feb 21, 2025
78e4966
logging rule scheduledemo added
YunchuWang Feb 21, 2025
5e29246
sample fb
YunchuWang Feb 22, 2025
6d66b5a
fb
YunchuWang Feb 22, 2025
d93986f
param
YunchuWang Feb 22, 2025
8086607
creatopt update
YunchuWang Feb 22, 2025
47d9af0
update scheduleconfig
YunchuWang Feb 22, 2025
aa2ee92
save
YunchuWang Feb 22, 2025
80ddc60
ischeduletaskclient interface
YunchuWang Feb 22, 2025
2ebb3ee
save
YunchuWang Feb 22, 2025
bd6a9a2
listschedule update
YunchuWang Feb 23, 2025
d20923b
remove create
YunchuWang Feb 23, 2025
45c1258
createschedule
YunchuWang Feb 23, 2025
2603859
save
YunchuWang Feb 23, 2025
f20dc86
createsche
YunchuWang Feb 23, 2025
330a935
create step 2
YunchuWang Feb 23, 2025
810bb80
create step 3
YunchuWang Feb 23, 2025
7e53bee
list
YunchuWang Feb 23, 2025
3a81480
save
YunchuWang Feb 23, 2025
bcadfc2
poll free part 1
YunchuWang Feb 23, 2025
5f00e2d
poll free part 2
YunchuWang Feb 23, 2025
2041f6b
poll free working
YunchuWang Feb 23, 2025
9bfcf1a
clean up
YunchuWang Feb 23, 2025
c96fdc3
more cleanup
YunchuWang Feb 23, 2025
0d40ae0
clean
YunchuWang Feb 23, 2025
c99cf1b
rename scheduleconsoleapp
YunchuWang Feb 24, 2025
b8be741
remove
YunchuWang Feb 24, 2025
4785899
save
YunchuWang Feb 24, 2025
9ed36bd
schedule webapp sample
YunchuWang Feb 24, 2025
0c5429f
add http client file for sample
YunchuWang Feb 24, 2025
f4f0b95
update
YunchuWang Feb 24, 2025
14edf50
save
YunchuWang Feb 24, 2025
ce7a4d6
finalize schedule webapi sample
YunchuWang Feb 24, 2025
3763f1a
Merge branch 'main' into wangbill/update-sln
YunchuWang Feb 24, 2025
291a6ca
partial fb addressed
YunchuWang Feb 24, 2025
d6b5e2a
more fb address
YunchuWang Feb 24, 2025
3267641
minimal
YunchuWang Feb 24, 2025
aed2a48
config
YunchuWang Feb 24, 2025
8853e14
fb
YunchuWang Feb 24, 2025
aeb7c6e
cleanup
YunchuWang Feb 24, 2025
0720922
save
YunchuWang Feb 24, 2025
280cb51
log
YunchuWang Feb 24, 2025
c1f21d5
throw
YunchuWang Feb 24, 2025
9eaf9b6
fb
YunchuWang Feb 24, 2025
7a74e20
fb
YunchuWang Feb 24, 2025
ea6befe
save
YunchuWang Feb 24, 2025
de8163d
Update src/ScheduledTasks/Client/ScheduledTaskClient.cs
YunchuWang Feb 24, 2025
de71f25
pagefix
YunchuWang Feb 25, 2025
bca682f
fix
YunchuWang Feb 25, 2025
cd0f8a0
fix
YunchuWang Feb 25, 2025
ae649c9
createorupdate
YunchuWang Feb 25, 2025
76f56b3
fb
YunchuWang Feb 25, 2025
b764a95
REFACTOR
YunchuWang Feb 25, 2025
41301ec
Merge branch 'main' into wangbill/update-sln
YunchuWang Feb 25, 2025
9362003
clean
YunchuWang Feb 25, 2025
71ed84f
Merge branch 'wangbill/update-sln' of https://github.com/microsoft/du…
YunchuWang Feb 25, 2025
ceaf8e4
updatre nextrunat computation
YunchuWang Feb 25, 2025
448eb30
save
YunchuWang Feb 25, 2025
067bd3a
fix
YunchuWang Feb 25, 2025
7b41375
excep
YunchuWang Feb 25, 2025
7d76f8c
rename schedulehandle and ch to abstract
YunchuWang Feb 25, 2025
c88c98d
renmae to scheduleclientimpl
YunchuWang Feb 25, 2025
19144a9
SAVE
YunchuWang Feb 25, 2025
4f5c71b
rename scheduledtaskclient and abstract
YunchuWang Feb 25, 2025
c64de7c
fix
YunchuWang Feb 25, 2025
cc00dd8
fix
YunchuWang Feb 25, 2025
6367860
fix
YunchuWang Feb 25, 2025
202be35
fix
YunchuWang Feb 25, 2025
34c5ee2
test p1
YunchuWang Feb 25, 2025
1077a0c
test p2
YunchuWang Feb 25, 2025
2e0917c
remove ScheduleAlreadyExistsException
YunchuWang Feb 25, 2025
69cb2f8
add createasync in scheduleclient
YunchuWang Feb 25, 2025
ca31f1f
fix unit tests
YunchuWang Feb 25, 2025
f43af2b
fix
YunchuWang Feb 25, 2025
03f5b45
fb
YunchuWang Feb 25, 2025
457bb88
fb
YunchuWang Feb 25, 2025
4987b00
fb
YunchuWang Feb 25, 2025
a610123
f
YunchuWang Feb 25, 2025
49b615d
fix
YunchuWang Feb 25, 2025
b5e8500
up
YunchuWang Feb 25, 2025
30c9a0c
fixed scheduletests
YunchuWang Feb 25, 2025
dfdf287
fix tests
YunchuWang Feb 26, 2025
ae97504
fix
YunchuWang Feb 26, 2025
c780eaa
more tests
YunchuWang Feb 26, 2025
4472dce
cleanup
YunchuWang Feb 26, 2025
740b550
save
YunchuWang Feb 26, 2025
24f5f64
unit test fix
YunchuWang Feb 26, 2025
368d926
cleanup comments
YunchuWang Feb 26, 2025
9802725
more tests
YunchuWang Feb 26, 2025
30b9877
cleanup
YunchuWang Feb 26, 2025
ed1bfd8
cleanup
YunchuWang Feb 26, 2025
e2ac9d8
link orch with schedule
YunchuWang Feb 26, 2025
a0c5408
fb
YunchuWang Feb 26, 2025
ac1924b
todo
YunchuWang Feb 26, 2025
1144044
fix test
YunchuWang Feb 26, 2025
e2b5c55
Update src/ScheduledTasks/Client/ScheduledTaskClient.cs
YunchuWang Feb 26, 2025
2b3b6bb
Update src/ScheduledTasks/Client/ScheduledTaskClient.cs
YunchuWang Feb 26, 2025
ee0a1c7
Update src/ScheduledTasks/Client/ScheduleClient.cs
YunchuWang Feb 26, 2025
65db0e2
refresh only active
YunchuWang Feb 26, 2025
f63d58c
Revert "refresh only active"
YunchuWang Feb 26, 2025
da7bc00
fb
YunchuWang Feb 28, 2025
4ac5908
Update ScheduleClientImpl.cs
YunchuWang Feb 28, 2025
bd3d662
rename schedule clients to default prefix
YunchuWang Feb 28, 2025
98767c8
fb
YunchuWang Mar 3, 2025
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
28 changes: 28 additions & 0 deletions Microsoft.DurableTask.sln
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared.AzureManaged.Tests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleAppMinimal", "samples\ConsoleAppMinimal\ConsoleAppMinimal.csproj", "{B48FACA9-A328-452A-BFAE-C4F60F9C7024}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScheduledTasks", "src\ScheduledTasks\ScheduledTasks.csproj", "{69ED743C-D616-4530-87E2-391D249D7368}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScheduleConsoleApp", "samples\ScheduleConsoleApp\ScheduleConsoleApp.csproj", "{A89B766C-987F-4C9F-8937-D0AB9FE640C8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScheduleWebApp", "samples\ScheduleWebApp\ScheduleWebApp.csproj", "{100348B5-4D97-4A3F-B777-AB14F276F8FE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScheduledTasks.Tests", "test\ScheduledTasks.Tests\ScheduledTasks.Tests.csproj", "{D2779F32-A548-44F8-B60A-6AC018966C79}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -223,6 +231,22 @@ Global
{B48FACA9-A328-452A-BFAE-C4F60F9C7024}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B48FACA9-A328-452A-BFAE-C4F60F9C7024}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B48FACA9-A328-452A-BFAE-C4F60F9C7024}.Release|Any CPU.Build.0 = Release|Any CPU
{69ED743C-D616-4530-87E2-391D249D7368}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{69ED743C-D616-4530-87E2-391D249D7368}.Debug|Any CPU.Build.0 = Debug|Any CPU
{69ED743C-D616-4530-87E2-391D249D7368}.Release|Any CPU.ActiveCfg = Release|Any CPU
{69ED743C-D616-4530-87E2-391D249D7368}.Release|Any CPU.Build.0 = Release|Any CPU
{A89B766C-987F-4C9F-8937-D0AB9FE640C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A89B766C-987F-4C9F-8937-D0AB9FE640C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A89B766C-987F-4C9F-8937-D0AB9FE640C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A89B766C-987F-4C9F-8937-D0AB9FE640C8}.Release|Any CPU.Build.0 = Release|Any CPU
{100348B5-4D97-4A3F-B777-AB14F276F8FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{100348B5-4D97-4A3F-B777-AB14F276F8FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{100348B5-4D97-4A3F-B777-AB14F276F8FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{100348B5-4D97-4A3F-B777-AB14F276F8FE}.Release|Any CPU.Build.0 = Release|Any CPU
{D2779F32-A548-44F8-B60A-6AC018966C79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2779F32-A548-44F8-B60A-6AC018966C79}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2779F32-A548-44F8-B60A-6AC018966C79}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2779F32-A548-44F8-B60A-6AC018966C79}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -265,6 +289,10 @@ Global
{CECADDB5-E30A-4CE2-8604-9AC596D4A2DC} = {E5637F81-2FB9-4CD7-900D-455363B142A7}
{3272C041-F81D-4C85-A4FB-2A700B5A7A9D} = {CECADDB5-E30A-4CE2-8604-9AC596D4A2DC}
{B48FACA9-A328-452A-BFAE-C4F60F9C7024} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17}
{69ED743C-D616-4530-87E2-391D249D7368} = {8AFC9781-F6F1-4696-BB4A-9ED7CA9D612B}
{A89B766C-987F-4C9F-8937-D0AB9FE640C8} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17}
{100348B5-4D97-4A3F-B777-AB14F276F8FE} = {EFF7632B-821E-4CFC-B4A0-ED4B24296B17}
{D2779F32-A548-44F8-B60A-6AC018966C79} = {E5637F81-2FB9-4CD7-900D-455363B142A7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AB41CB55-35EA-4986-A522-387AB3402E71}
Expand Down
16 changes: 16 additions & 0 deletions samples/ScheduleConsoleApp/Activities/GetStockPrice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.DurableTask;

namespace ScheduleConsoleApp.Activities;

[DurableTask]
public class GetStockPrice : TaskActivity<string, decimal>
{
public override Task<decimal> RunAsync(TaskActivityContext context, string symbol)
{
// Mock implementation - would normally call stock API
return Task.FromResult(100.00m);
}
}
29 changes: 29 additions & 0 deletions samples/ScheduleConsoleApp/Orchestrators/StockPriceOrchestrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.DurableTask;
using Microsoft.Extensions.Logging;

[DurableTask]
public class StockPriceOrchestrator : TaskOrchestrator<string, string>
{
public override async Task<string> RunAsync(TaskOrchestrationContext context, string symbol)
{
var logger = context.CreateReplaySafeLogger("DemoOrchestration");
logger.LogInformation("Getting stock price for: {symbol}", symbol);
try
{
// Get current stock price
decimal currentPrice = await context.CallGetStockPriceAsync(symbol);

logger.LogInformation("Current price for {symbol} is ${price:F2}", symbol, currentPrice);

return $"Stock {symbol} price: ${currentPrice:F2} at {DateTime.UtcNow}";
}
catch (Exception ex)
{
logger.LogError(ex, "Error processing stock price for {symbol}", symbol);
throw;
}
}
}
57 changes: 57 additions & 0 deletions samples/ScheduleConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.DurableTask;
using Microsoft.DurableTask.Client;
using Microsoft.DurableTask.Client.AzureManaged;
using Microsoft.DurableTask.ScheduledTasks;
using Microsoft.DurableTask.Worker;
using Microsoft.DurableTask.Worker.AzureManaged;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using ScheduleConsoleApp;

HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);

// Get configuration
string connectionString = builder.Configuration.GetValue<string>("DURABLE_TASK_SCHEDULER_CONNECTION_STRING")
?? throw new InvalidOperationException("Missing required configuration 'DURABLE_TASK_SCHEDULER_CONNECTION_STRING'");

// Configure the worker
builder.Services.AddDurableTaskWorker(builder =>
{
// Add the Schedule entity and demo orchestration
builder.AddTasks(r => r.AddAllGeneratedTasks());

// Enable scheduled tasks support
builder.UseDurableTaskScheduler(connectionString);
builder.UseScheduledTasks();
});

// Configure the client
builder.Services.AddDurableTaskClient(builder =>
{
builder.UseDurableTaskScheduler(connectionString);
builder.UseScheduledTasks();
});

// Configure console logging
builder.Services.AddLogging(logging =>
{
logging.AddSimpleConsole(options =>
{
options.SingleLine = true;
options.UseUtcTimestamp = true;
options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ ";
});
});

IHost host = builder.Build();
await host.StartAsync();

// Run the schedule operations
ScheduledTaskClient scheduledTaskClient = host.Services.GetRequiredService<ScheduledTaskClient>();
await ScheduleDemo.RunDemoAsync(scheduledTaskClient);

await host.StopAsync();
21 changes: 21 additions & 0 deletions samples/ScheduleConsoleApp/ScheduleConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting"/>
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Grpc.Net.Client" />
<PackageReference Include="Microsoft.DurableTask.Generators" OutputItemType="Analyzer" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Client\AzureManaged\Client.AzureManaged.csproj" />
<ProjectReference Include="..\..\src\Worker\AzureManaged\Worker.AzureManaged.csproj" />
<ProjectReference Include="..\..\src\ScheduledTasks\ScheduledTasks.csproj" />
</ItemGroup>
</Project>
84 changes: 84 additions & 0 deletions samples/ScheduleConsoleApp/ScheduleDemo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.DurableTask;
using Microsoft.DurableTask.ScheduledTasks;

namespace ScheduleConsoleApp;

/// <summary>
/// Demonstrates various schedule operations in a sample application.
/// </summary>
static class ScheduleDemo
{
public static async Task RunDemoAsync(ScheduledTaskClient scheduledTaskClient)
{
ArgumentNullException.ThrowIfNull(scheduledTaskClient);

try
{
await DeleteExistingSchedulesAsync(scheduledTaskClient);
await CreateAndManageScheduleAsync(scheduledTaskClient);
}
catch (Exception ex)
{
Console.WriteLine($"One of your schedule operations failed, please fix and rerun: {ex.Message}");
}
}

static async Task DeleteExistingSchedulesAsync(ScheduledTaskClient scheduledTaskClient)
{
// Define the initial query with the desired page size
ScheduleQuery query = new ScheduleQuery { PageSize = 100 };

// Retrieve the pageable collection of schedule IDs
AsyncPageable<ScheduleDescription> schedules = scheduledTaskClient.ListSchedulesAsync(query);

// Delete each existing schedule
await foreach (ScheduleDescription schedule in schedules)
{
ScheduleClient scheduleClient = scheduledTaskClient.GetScheduleClient(schedule.ScheduleId);
await scheduleClient.DeleteAsync();
Console.WriteLine($"Deleted schedule {schedule.ScheduleId}");
}
}

static async Task CreateAndManageScheduleAsync(ScheduledTaskClient scheduledTaskClient)
{
// Create schedule options that runs every 4 seconds
ScheduleCreationOptions scheduleOptions = new ScheduleCreationOptions(
"demo-schedule101",
nameof(StockPriceOrchestrator),
TimeSpan.FromSeconds(4))
{
StartAt = DateTimeOffset.UtcNow,
OrchestrationInput = "MSFT"
};

// Create the schedule and get a handle to it
ScheduleClient scheduleClient = await scheduledTaskClient.CreateScheduleAsync(scheduleOptions);

// Get and print the initial schedule description
await PrintScheduleDescriptionAsync(scheduleClient);

// Pause the schedule
Console.WriteLine("\nPausing schedule...");
await scheduleClient.PauseAsync();
await PrintScheduleDescriptionAsync(scheduleClient);

// Resume the schedule
Console.WriteLine("\nResuming schedule...");
await scheduleClient.ResumeAsync();
await PrintScheduleDescriptionAsync(scheduleClient);

// Wait for a while to let the schedule run
await Task.Delay(TimeSpan.FromMinutes(30));
}

static async Task PrintScheduleDescriptionAsync(ScheduleClient scheduleClient)
{
ScheduleDescription scheduleDescription = await scheduleClient.DescribeAsync();
Console.WriteLine(scheduleDescription);
Console.WriteLine("\n\n");
}
}
10 changes: 10 additions & 0 deletions samples/ScheduleConsoleApp/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Warning",
"ScheduleConsoleApp": "Debug",
"DemoOrchestration": "Debug"
}
}
}
40 changes: 40 additions & 0 deletions samples/ScheduleWebApp/Models/CreateScheduleRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace ScheduleWebApp.Models;

/// <summary>
/// Represents a request to create a new schedule.
/// </summary>
public class CreateScheduleRequest
{
/// <summary>
/// Gets or sets the unique identifier for the schedule.
/// </summary>
public string Id { get; set; } = default!;

/// <summary>
/// Gets or sets the name of the orchestration to be scheduled.
/// </summary>
public string OrchestrationName { get; set; } = default!;

/// <summary>
/// Gets or sets the input data for the orchestration.
/// </summary>
public string? Input { get; set; }

/// <summary>
/// Gets or sets the time interval between schedule executions.
/// </summary>
public TimeSpan Interval { get; set; }

/// <summary>
/// Gets or sets the time when the schedule should start.
/// </summary>
public DateTimeOffset? StartAt { get; set; }

/// <summary>
/// Gets or sets the time when the schedule should end.
/// </summary>
public DateTimeOffset? EndAt { get; set; }
}
35 changes: 35 additions & 0 deletions samples/ScheduleWebApp/Models/UpdateScheduleRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace ScheduleWebApp.Models;

/// <summary>
/// Represents a request to update an existing schedule.
/// </summary>
public class UpdateScheduleRequest
{
/// <summary>
/// Gets or sets the name of the orchestration to be scheduled.
/// </summary>
public string OrchestrationName { get; set; } = default!;

/// <summary>
/// Gets or sets the input data for the orchestration.
/// </summary>
public string? Input { get; set; }

/// <summary>
/// Gets or sets the time interval between schedule executions.
/// </summary>
public TimeSpan Interval { get; set; }

/// <summary>
/// Gets or sets the time when the schedule should start.
/// </summary>
public DateTimeOffset? StartAt { get; set; }

/// <summary>
/// Gets or sets the time when the schedule should end.
/// </summary>
public DateTimeOffset? EndAt { get; set; }
}
30 changes: 30 additions & 0 deletions samples/ScheduleWebApp/Orchestrations/CacheClearingOrchestrator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.DurableTask;

namespace ScheduleWebApp.Orchestrations;

public class CacheClearingOrchestrator : TaskOrchestrator<string, string>
{
public override async Task<string> RunAsync(TaskOrchestrationContext context, string scheduleId)
{
ILogger logger = context.CreateReplaySafeLogger(nameof(CacheClearingOrchestrator));
try
{
logger.LogInformation("Starting CacheClearingOrchestration for schedule ID: {ScheduleId}", scheduleId);

// Simulate cache clearing
await Task.Delay(TimeSpan.FromSeconds(5));

logger.LogInformation("CacheClearingOrchestration completed for schedule ID: {ScheduleId}", scheduleId);

return "ok";
}
catch (Exception ex)
{
logger.LogError(ex, "Error in CacheClearingOrchestration for schedule ID: {ScheduleId}", scheduleId);
throw;
}
}
}
Loading
Loading