-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate server run endpoint to Azure Function
- Loading branch information
1 parent
68053eb
commit a4cf3a9
Showing
27 changed files
with
245 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<AzureFunctionsVersion>v3</AzureFunctionsVersion> | ||
<RootNamespace>blazoract.Api</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" /> | ||
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.3" /> | ||
<PackageReference Include="Microsoft.DotNet.Interactive.CSharp" Version="1.0.0-beta.20426.1" /> | ||
<PackageReference Include="FSharp.Compiler.Private.Scripting" Version="11.0.0-beta.20428.1" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Shared\blazoract.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="host.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="local.settings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<CopyToPublishDirectory>Never</CopyToPublishDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.DotNet.Interactive.CSharp; | ||
using Microsoft.DotNet.Interactive; | ||
using Microsoft.DotNet.Interactive.Events; | ||
using Microsoft.DotNet.Interactive.Commands; | ||
using blazoract.Shared; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Net.Http; | ||
using Newtonsoft.Json; | ||
|
||
namespace blazoract.Api | ||
{ | ||
public class KernelFunction | ||
{ | ||
private CompositeKernel _kernel; | ||
public KernelFunction(CompositeKernel kernel) | ||
{ | ||
this._kernel = kernel; | ||
} | ||
|
||
[FunctionName("RunCode")] | ||
public async Task<IActionResult> Run( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "code/run")] HttpRequest req, | ||
ILogger log) | ||
{ | ||
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); | ||
var cell = JsonConvert.DeserializeObject<ExecuteRequest>(requestBody); | ||
|
||
Console.WriteLine(requestBody); | ||
|
||
var request = await _kernel.SendAsync(new SubmitCode(cell.Input), new CancellationToken()); | ||
var result = new ExecuteResult(); | ||
request.KernelEvents.Subscribe(x => | ||
{ | ||
Console.WriteLine($"Received event: {x}"); | ||
switch (x) | ||
{ | ||
case DisplayEvent displayEvent: | ||
result.Output = displayEvent.Value?.ToString(); | ||
break; | ||
case CommandFailed commandFailed: | ||
result.CommandFailedMessage = commandFailed.Message; | ||
break; | ||
} | ||
}); | ||
|
||
return new OkObjectResult(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.Http; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.DotNet.Interactive.CSharp; | ||
using Microsoft.DotNet.Interactive; | ||
using Microsoft.DotNet.Interactive.Events; | ||
using Microsoft.DotNet.Interactive.Commands; | ||
using blazoract.Shared; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Net.Http; | ||
using Newtonsoft.Json; | ||
|
||
namespace blazoract.Api | ||
{ | ||
public class KernelFunction | ||
{ | ||
private CompositeKernel _kernel; | ||
public KernelFunction(CompositeKernel kernel) | ||
{ | ||
this._kernel = kernel; | ||
} | ||
|
||
[FunctionName("RunCode")] | ||
public async Task<IActionResult> Run( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "code/run")] HttpRequest req, | ||
ILogger log) | ||
{ | ||
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); | ||
var cell = JsonConvert.DeserializeObject<ExecuteRequest>(requestBody); | ||
|
||
var request = await _kernel.SendAsync(new SubmitCode(cell.Input), new CancellationToken()); | ||
var result = new ExecuteResult(); | ||
request.KernelEvents.Subscribe(x => | ||
{ | ||
Console.WriteLine($"Received event: {x}"); | ||
switch (x) | ||
{ | ||
case DisplayEvent displayEvent: | ||
result.Output = displayEvent.Value?.ToString(); | ||
break; | ||
case CommandFailed commandFailed: | ||
result.CommandFailedMessage = commandFailed.Message; | ||
break; | ||
} | ||
}); | ||
|
||
return new OkObjectResult(result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"profiles": { | ||
"Api": { | ||
"commandName": "Project", | ||
"commandLineArgs": "start --cors *" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"dependencies": { | ||
"storage1": { | ||
"type": "storage", | ||
"connectionId": "AzureWebJobsStorage" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"dependencies": { | ||
"storage1": { | ||
"type": "storage.emulator", | ||
"connectionId": "AzureWebJobsStorage" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.Azure.Functions.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.DotNet.Interactive.CSharp; | ||
using Microsoft.DotNet.Interactive; | ||
|
||
[assembly: FunctionsStartup(typeof(blazoract.Api.Startup))] | ||
|
||
namespace blazoract.Api | ||
{ | ||
public class Startup : FunctionsStartup | ||
{ | ||
public override void Configure(IFunctionsHostBuilder builder) | ||
{ | ||
builder.Services.AddSingleton<CompositeKernel>(new CompositeKernel() { | ||
new CSharpKernel().UseDefaultFormatting().UseDotNetVariableSharing() | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingExcludedTypes": "Request", | ||
"samplingSettings": { | ||
"isEnabled": true | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"IsEncrypted": false, | ||
"Values": { | ||
"AzureWebJobsStorage": "UseDevelopmentStorage=true", | ||
"FUNCTIONS_WORKER_RUNTIME": "dotnet" | ||
}, | ||
"Host": { | ||
"LocalHttpPort": 7071, | ||
"CORS": "*", | ||
"CORSCredentials": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.