-
Notifications
You must be signed in to change notification settings - Fork 27
Init json quickstart updates #50
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
Changes from all commits
25649ae
ec9dee5
05eee73
33465be
bfb6259
d7b7df5
ea01fdf
cbfac52
1a1b4cc
5f117fa
d44cf05
e30899a
0e65ffd
a75972e
9db63ff
71fa8c6
8d41186
e9ee75e
9b6e645
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,20 @@ | |
|
|
||
| # Quick .NET Core 2.2 Action | ||
|
|
||
| A .NET Core action is a .NET Core class library with a method called `Main` that has the exact signature as follows: | ||
| A .NET Core action is a .NET Core class library with a method called `Main` or `MainAsync` that has the exact signature as follows: | ||
|
|
||
| Synchronous: | ||
|
|
||
| ```csharp | ||
| public Newtonsoft.Json.Linq.JObject Main(Newtonsoft.Json.Linq.JObject); | ||
| ``` | ||
|
|
||
| Asynchronous: | ||
|
|
||
| ```csharp | ||
| public async System.Threading.Tasks.Task<Newtonsoft.Json.Linq.JObject> MainAsync(Newtonsoft.Json.Linq.JObject); | ||
| ``` | ||
|
|
||
| In order to compile, test and archive .NET Core projects, you must have the [.NET Core SDK](https://www.microsoft.com/net/download) installed locally and the environment variable `DOTNET_HOME` set to the location where the `dotnet` executable can be found. | ||
|
|
||
| For example, create a C# project called `Apache.OpenWhisk.Example.Dotnet`: | ||
|
|
@@ -37,11 +45,13 @@ cd Apache.OpenWhisk.Example.Dotnet | |
| Install the [Newtonsoft.Json](https://www.newtonsoft.com/json) NuGet package as follows: | ||
|
|
||
| ```bash | ||
| dotnet add package Newtonsoft.Json -v 12.0.2 | ||
| dotnet add package Newtonsoft.Json -v 13.0.1 | ||
| ``` | ||
|
|
||
| Now create a file called `Hello.cs` with the following content: | ||
|
|
||
| Synchronous example: | ||
|
|
||
| ```csharp | ||
| using System; | ||
| using Newtonsoft.Json.Linq; | ||
|
|
@@ -64,6 +74,32 @@ namespace Apache.OpenWhisk.Example.Dotnet | |
| } | ||
| ``` | ||
|
|
||
| Asynchronous example: | ||
|
|
||
| ```csharp | ||
| using System; | ||
| using Newtonsoft.Json.Linq; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Apache.OpenWhisk.Example.Dotnet | ||
| { | ||
| public class Hello | ||
| { | ||
| public async Task<JObject> MainAsync(JObject args) | ||
| { | ||
| await Task.Delay(10); // Just do a delay to have an async/await process occur. | ||
| string name = "stranger"; | ||
| if (args.ContainsKey("name")) { | ||
| name = args["name"].ToString(); | ||
| } | ||
| JObject message = new JObject(); | ||
| message.Add("greeting", new JValue($"Hello, {name}!")); | ||
| return (message); | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Publish the project as follows: | ||
|
|
||
| ```bash | ||
|
|
@@ -79,17 +115,27 @@ zip -r -0 helloDotNet.zip * | |
|
|
||
| You need to specify the name of the function handler using `--main` argument. | ||
| The value for `main` needs to be in the following format: | ||
| `{Assembly}::{Class Full Name}::{Method}`, e.q., | ||
| `Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main` | ||
| `{Assembly}::{Class Full Name}::{Method}`, e.q.: | ||
|
|
||
| + Synchronous: `Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main` | ||
| + Asynchronous: `Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::MainAsync` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An example of the user having to make a decision where they technically don't need to, adding friction.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could simplify the docs - to show the sync case with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glad to hear you agree. After looking again at @shawnallen85 's changes though, I agree there is one spot it's important to show both. That's at the very top where it says "that has the exact signature as follows", because in the async case, the signature is materially different. I think to keep it simple, we should just use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to take a shot at editing the quick start along these lines? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, this PR is already merged in, so I'll do a new PR when I have time (most of my OpenWhisking is done on the weekends right now) with suggested doc changes and ask for a review. I think for this PR, we're all set. |
||
|
|
||
| ## Create the .NET Core Action | ||
|
|
||
| To use on a deployment of OpenWhisk that contains the runtime as a kind: | ||
|
|
||
| Synchronous: | ||
|
|
||
| ```bash | ||
| wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::Main --kind dotnet:2.2 | ||
| ``` | ||
|
|
||
| Asynchronous: | ||
|
|
||
| ```bash | ||
| wsk action update helloDotNet helloDotNet.zip --main Apache.OpenWhisk.Example.Dotnet::Apache.OpenWhisk.Example.Dotnet.Hello::MainAsync --kind dotnet:2.2 | ||
| ``` | ||
|
|
||
| ## Invoke the .NET Core Action | ||
|
|
||
| Action invocation is the same for .NET Core actions as it is for Swift and JavaScript actions: | ||
|
|
@@ -150,7 +196,7 @@ Install dependencies from the root directory on $OPENWHISK_HOME repository | |
| ```bash | ||
| pushd $OPENWHISK_HOME | ||
| ./gradlew install | ||
| podd $OPENWHISK_HOME | ||
| popd | ||
| ``` | ||
|
|
||
| Using gradle to run all tests | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this just a .NET convention, that async methods should end in "Async"? (https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/task-asynchronous-programming-model)
I'd argue that that should be up to the OpenWhisk user. In the end, I imagine the usefulness of this convention is that people writing code and using this function will see right away that it returns
TaskorTask<T>. In this case, they're coding a function that the runtime will use, so they don't get any value out of following that convention.Right now, the runtime detects whether it needs to await the method, and if so, it does. This means the quickstarts before this PR can be used whether the user function is async or sync, and they're simpler that way because the user doesn't need to worry about following different paths depending on if they're writing an async or sync Main method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are just provided as examples of how you can create it -- it isn't gospel -- the user still has the option of defining the functions full name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the user has the option to define the function name any way they like, I think the quickstarts should be about getting started as quick as possible with as few decisions to make as possible. Someone new to OpenWhisk is likely to be more interested in getting up and running easily than tweaking a function. They wouldn't even have a function yet.