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

Added .NET client for new Dapr Jobs API support #1320

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
3301b03
Added .NET client for new Dapr Jobs API support
WhitWaldo Jul 6, 2024
5732ca5
Removed explicit .NET 7 targeting
WhitWaldo Jul 8, 2024
debf7ad
Using `AddDaprJobsClient` for consistency with other SDKs
WhitWaldo Jul 8, 2024
c3b2a8c
Refactored the DaprClientBuilder out to a common project. Updated dep…
WhitWaldo Jul 9, 2024
12fb796
Renamed to reflect that it's a Dapr exception
WhitWaldo Jul 9, 2024
cfd74f7
Updated solution to propertly find Dapr.Common in /src directory
WhitWaldo Jul 9, 2024
24ae98c
Added scheduler.proto and updated project file to autogenerate approp…
WhitWaldo Jul 9, 2024
4e5d856
Removed unused type
WhitWaldo Jul 9, 2024
d0e577b
Fixed an XML comment that didn't make sense
WhitWaldo Jul 9, 2024
5faa914
Implemented service-specific equivalent of DaprClientBuilder for Dapr…
WhitWaldo Jul 9, 2024
4ca40eb
Updated to support DaprJobClientOptions which specify the App ID and …
WhitWaldo Jul 9, 2024
b0291bf
Added DI registration extensions that support options
WhitWaldo Jul 9, 2024
797be63
Refactored out DaprException to common project - retained same namesp…
WhitWaldo Jul 9, 2024
c4b028b
Fixed method not returning properly
WhitWaldo Jul 9, 2024
c15e090
Added extension method for parsing a TimeSpan from a Golang interval
WhitWaldo Jul 9, 2024
f3a7c41
Implemented all but the Watch method on the client
WhitWaldo Jul 9, 2024
6157cd0
Added missing copyright headers
WhitWaldo Jul 9, 2024
0f0954d
Finished out most of the WatchJobs method.
WhitWaldo Jul 9, 2024
2cdd554
Adding attribute to mark endpoints for Job trigger invocations
WhitWaldo Jul 10, 2024
e713661
Partially through bidirectional watcher implementation, but stopping …
WhitWaldo Jul 10, 2024
49c78eb
Updates to use the correct protos (dapr runtime, not the scheduler se…
WhitWaldo Jul 10, 2024
e76b323
Added default null values
WhitWaldo Jul 10, 2024
79e56d6
Added schedule job overloads for when the developer doesn't want to s…
WhitWaldo Jul 10, 2024
9723ff5
Rather than 6 overloads of the same method, changed the names of each…
WhitWaldo Jul 10, 2024
6bd99c5
Solution update
WhitWaldo Jul 10, 2024
63df29d
Removed serialization from SDK - swapping to only accepting and retur…
WhitWaldo Jul 11, 2024
d6cbf51
Update to use ReadOnlyMemory<byte> instead of byte[]
WhitWaldo Jul 12, 2024
bcdf08b
Refactored the generic client builder so that less identical code nee…
WhitWaldo Jul 12, 2024
597ac0d
Updating constructor to use protected instead of public
WhitWaldo Jul 12, 2024
c08376a
Neglected to update DaprJobsGrpcClient to reflect signature changes. …
WhitWaldo Jul 12, 2024
ff3cf9c
Removed DaprJobClientOptions as no longer needed since we're using th…
WhitWaldo Jul 15, 2024
3e1b0f3
Consolidated all the extensions
WhitWaldo Jul 15, 2024
e44dca0
Renamed to ScheduledJobAttribute to match the API name
WhitWaldo Jul 15, 2024
5b7600d
Adding ASP.NET Core to package to add route builder extension support
WhitWaldo Jul 15, 2024
c15fa66
Added another registration overload so the developer isn't forced to …
WhitWaldo Jul 15, 2024
a29a4dd
Shifted schedule deserialization into the JobDetails record itself an…
WhitWaldo Jul 15, 2024
1252ef6
Adding JobsSample project to prove out API
WhitWaldo Jul 15, 2024
4057ca5
Removed tentatively unnecessary attribute since we're relying on ASP.…
WhitWaldo Jul 15, 2024
449609e
Simplified example
WhitWaldo Jul 15, 2024
0101327
Fixing unit tests - resolving errors due to lack of InternalsVisibleT…
WhitWaldo Jul 15, 2024
c860260
Fixed last locally-broken test client due to lack of InternalsVisible…
WhitWaldo Jul 15, 2024
fb983a9
Updated name of invocation endpoint registration method to include "D…
WhitWaldo Jul 15, 2024
b3db843
Building out unit tests
WhitWaldo Jul 16, 2024
f6333e9
Removed unused using
WhitWaldo Jul 16, 2024
2bf4cfd
Added some null validation
WhitWaldo Jul 16, 2024
e5d5646
Refactored to use the same naming convention as the other types in th…
WhitWaldo Jul 16, 2024
61b1978
Building on last commit, updated extension names
WhitWaldo Jul 16, 2024
90a5fe1
Adding more unit tests
WhitWaldo Jul 16, 2024
e674fa8
Removed unused type
WhitWaldo Jul 16, 2024
4215d87
Updated to use int? instead of uint? for repeats parameter. Added che…
WhitWaldo Jul 16, 2024
8e72f5a
Added support for IDisposable
WhitWaldo Jul 16, 2024
20be1d5
Updated to support provisioning an HttpClient from IHttpClientFactory…
WhitWaldo Jul 16, 2024
1780337
Fixed an issue with the API token not being properly passed into clie…
WhitWaldo Jul 16, 2024
22d3a17
Another tweak to finalize fix for Dapr API token - updated tests as well
WhitWaldo Jul 16, 2024
60b1c88
Adding helper deserialization extension methods + tests
WhitWaldo Jul 16, 2024
db4f93f
Added more helper extension methods for serializing strings and JSON-…
WhitWaldo Jul 16, 2024
62052e6
Naming correction to ensure parameter names are similar from one sche…
WhitWaldo Jul 16, 2024
9fef177
Removed JsonSerializerOptions support from DaprJobsClient as it's not…
WhitWaldo Jul 16, 2024
39dbcf8
First pass at updating documentation
WhitWaldo Jul 16, 2024
8d59928
Updated packages to fix build errors because of everything's dependen…
WhitWaldo Jul 16, 2024
4a101a6
Forced to update these packages to 8.0.0 because of other transitive …
WhitWaldo Jul 16, 2024
ffdb47b
Fixed build errors introduced by the transient reference to Microsoft…
WhitWaldo Jul 16, 2024
8eb57f5
Fixed issues in the unit tests caused by over-eager fix on the Dapr A…
WhitWaldo Jul 16, 2024
81f9ef5
Merge branch 'master' into job-api-sdk
WhitWaldo Jul 24, 2024
2e26e13
Fixed incorrect unit test
WhitWaldo Jul 25, 2024
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This repo builds the following packages:
- Dapr.Actors.AspNetCore
- Dapr.Extensions.Configuration
- Dapr.Workflow
- Dapr.Jobs

### Prerequisites

Expand Down
38 changes: 38 additions & 0 deletions all.sln
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapr.E2E.Test.Actors.Genera
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cryptography", "examples\Client\Cryptography\Cryptography.csproj", "{C74FBA78-13E8-407F-A173-4555AEE41FF3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapr.Jobs", "src\Dapr.Jobs\Dapr.Jobs.csproj", "{D34F9326-8D8C-43C4-975B-7201A9C97E6E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapr.Jobs.Test", "test\Dapr.Jobs.Test\Dapr.Jobs.Test.csproj", "{EDEE625E-6815-40E1-935F-35129771A0F8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dapr.Common", "src\Dapr.Common\Dapr.Common.csproj", "{3E075F71-185E-4C09-9449-79D21A958487}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Jobs", "Jobs", "{4DA40205-C38D-4E19-BD9A-0F18EE06CBAB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JobsSample", "examples\Jobs\JobsSample\JobsSample.csproj", "{11E59564-D677-4137-81BD-CF0B142530DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapr.Common.Test", "test\Dapr.Common.Test\Dapr.Common.Test.csproj", "{229BB84C-69A4-4A40-AD49-1FD6C237E0C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -290,6 +302,26 @@ Global
{C74FBA78-13E8-407F-A173-4555AEE41FF3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C74FBA78-13E8-407F-A173-4555AEE41FF3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C74FBA78-13E8-407F-A173-4555AEE41FF3}.Release|Any CPU.Build.0 = Release|Any CPU
{D34F9326-8D8C-43C4-975B-7201A9C97E6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D34F9326-8D8C-43C4-975B-7201A9C97E6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D34F9326-8D8C-43C4-975B-7201A9C97E6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D34F9326-8D8C-43C4-975B-7201A9C97E6E}.Release|Any CPU.Build.0 = Release|Any CPU
{EDEE625E-6815-40E1-935F-35129771A0F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDEE625E-6815-40E1-935F-35129771A0F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDEE625E-6815-40E1-935F-35129771A0F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDEE625E-6815-40E1-935F-35129771A0F8}.Release|Any CPU.Build.0 = Release|Any CPU
{3E075F71-185E-4C09-9449-79D21A958487}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E075F71-185E-4C09-9449-79D21A958487}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E075F71-185E-4C09-9449-79D21A958487}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E075F71-185E-4C09-9449-79D21A958487}.Release|Any CPU.Build.0 = Release|Any CPU
{11E59564-D677-4137-81BD-CF0B142530DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11E59564-D677-4137-81BD-CF0B142530DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11E59564-D677-4137-81BD-CF0B142530DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11E59564-D677-4137-81BD-CF0B142530DB}.Release|Any CPU.Build.0 = Release|Any CPU
{229BB84C-69A4-4A40-AD49-1FD6C237E0C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{229BB84C-69A4-4A40-AD49-1FD6C237E0C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{229BB84C-69A4-4A40-AD49-1FD6C237E0C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{229BB84C-69A4-4A40-AD49-1FD6C237E0C5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -343,6 +375,12 @@ Global
{AF89083D-4715-42E6-93E9-38497D12A8A6} = {DD020B34-460F-455F-8D17-CF4A949F100B}
{B5CDB0DC-B26D-48F1-B934-FE5C1C991940} = {DD020B34-460F-455F-8D17-CF4A949F100B}
{C74FBA78-13E8-407F-A173-4555AEE41FF3} = {A7F41094-8648-446B-AECD-DCC2CC871F73}
{D34F9326-8D8C-43C4-975B-7201A9C97E6E} = {27C5D71D-0721-4221-9286-B94AB07B58CF}
{EDEE625E-6815-40E1-935F-35129771A0F8} = {DD020B34-460F-455F-8D17-CF4A949F100B}
{3E075F71-185E-4C09-9449-79D21A958487} = {27C5D71D-0721-4221-9286-B94AB07B58CF}
{4DA40205-C38D-4E19-BD9A-0F18EE06CBAB} = {D687DDC4-66C5-4667-9E3A-FD8B78ECAA78}
{11E59564-D677-4137-81BD-CF0B142530DB} = {4DA40205-C38D-4E19-BD9A-0F18EE06CBAB}
{229BB84C-69A4-4A40-AD49-1FD6C237E0C5} = {DD020B34-460F-455F-8D17-CF4A949F100B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65220BF2-EAE1-4CB2-AA58-EBE80768CB40}
Expand Down
13 changes: 13 additions & 0 deletions examples/Jobs/JobsSample/JobsSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Dapr.Jobs\Dapr.Jobs.csproj" />
</ItemGroup>

</Project>
41 changes: 41 additions & 0 deletions examples/Jobs/JobsSample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma warning disable CS0618 // Type or member is obsolete
using System.Text;
using Dapr.Jobs;
using Dapr.Jobs.Extensions;
using Dapr.Jobs.Models.Responses;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddDaprJobsClient();

var app = builder.Build();

// Configure the HTTP request pipeline.

app.MapScheduledJob("myJob", (ILogger logger, JobDetails details) =>
{
logger.LogInformation("Received trigger invocation for 'myJob'");

if (details.Payload is not null)
{
var deserializedPayload = Encoding.UTF8.GetString(details.Payload.Value.ToArray());

logger.LogInformation($"Received invocation for the 'myJob' job with payload '{deserializedPayload}'");
return;
}
logger.LogInformation("Failed to deserialize payload for trigger invocation");
});

app.Run();

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

logger.LogInformation("Scheduling one-time job 'myJob' to execute 10 seconds from now");
await daprJobsClient.ScheduleOneTimeJobAsync("myJob", DateTime.UtcNow.AddSeconds(10),
Encoding.UTF8.GetBytes("This is a test"));
logger.LogInformation("Scheduled one-time job 'myJob'");


#pragma warning restore CS0618 // Type or member is obsolete
30 changes: 30 additions & 0 deletions examples/Jobs/JobsSample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:40682",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5227",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
8 changes: 8 additions & 0 deletions examples/Jobs/JobsSample/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions examples/Jobs/JobsSample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
2 changes: 1 addition & 1 deletion properties/IsExternalInit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ namespace System.Runtime.CompilerServices
internal static class IsExternalInit
{
}

}
1 change: 1 addition & 0 deletions src/Dapr.AspNetCore/Dapr.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<ProjectReference Include="..\Dapr.Client\Dapr.Client.csproj" />
<ProjectReference Include="..\Dapr.Common\Dapr.Common.csproj" />
</ItemGroup>

</Project>
3 changes: 1 addition & 2 deletions src/Dapr.AspNetCore/DaprServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Copyright 2021 The Dapr Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -14,7 +14,6 @@
namespace Microsoft.Extensions.DependencyInjection
{
using System;
using System.Linq;
using Dapr.Client;
using Extensions;

Expand Down
3 changes: 1 addition & 2 deletions src/Dapr.Client/Dapr.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
<PackageReference Include="Grpc.Tools" Version="2.47.0" PrivateAssets="All" />
<PackageReference Include="Google.Api.CommonProtos" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<Folder Include="Protos\" />
<ProjectReference Include="..\Dapr.Common\Dapr.Common.csproj" />
</ItemGroup>

</Project>
Loading
Loading