commit ef058becacfe20f69daff83dff9de5d8216b1170 Author: Ayan Poddar Date: Fri May 9 13:18:36 2025 +0530 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97a330f --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ + +# Build results +bin/ +obj/ + +# IDE cruft +/.vs +/.vscode +/.idea diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..c3f78a2 --- /dev/null +++ b/Program.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.Http.HttpResults; +using Temporalio.Client; +using Temporalio.Extensions.Hosting; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi +builder.Services.AddOpenApi(); +builder.Services + .AddHostedTemporalWorker( + clientTargetHost: "localhost:7233", + clientNamespace: "default", + taskQueue: MyWorkflow.TaskQueue) + .AddWorkflow(); + +builder.Services.AddSingleton(ct => TemporalClient.ConnectAsync(new() +{ + TargetHost = "localhost:7233" +})); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.MapOpenApi(); +} + +app.UseHttpsRedirection(); + +app.MapGet("/", async (Task clientTask, string? name) => +{ + var client = await clientTask; + var isRunning = await client.StartWorkflowAsync( + (MyWorkflow wf) => wf.RunAsync(name ?? "Temporal"), + new(id: $"aspnet-sample-workflow-{Guid.NewGuid()}", taskQueue: MyWorkflow.TaskQueue)); + return Results.Ok(isRunning.Id); +}); + +app.MapGet("/Get", async (Task clientTask, string GetId) => +{ + var client = await clientTask; + var handle = client.GetWorkflowHandle(GetId); + var responce = await handle.DescribeAsync(); + if (responce.Status != Temporalio.Api.Enums.V1.WorkflowExecutionStatus.Completed) + return Results.Ok(responce.Status.ToString()); + + var result = await handle.GetResultAsync(); + return Results.Ok(result); +}); +app.Run(); \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..a152c90 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5167", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7127;http://localhost:5167", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/WorkerSerVice.cs b/WorkerSerVice.cs new file mode 100644 index 0000000..218c168 --- /dev/null +++ b/WorkerSerVice.cs @@ -0,0 +1,18 @@ + +using System.Threading; +using Temporalio.Client; +using Temporalio.Worker; +using Temporalio.Workflows; + +[Workflow] +public class MyWorkflow +{ + public const string TaskQueue = "asp-net-sample"; + + [WorkflowRun] + public async Task RunAsync(string name) + { + await Workflow.DelayAsync(30 * 1000); + return $"Hello, {name}! welcome {TaskQueue}"; + } +} \ No newline at end of file diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/aspnetnew.csproj b/aspnetnew.csproj new file mode 100644 index 0000000..8fdad31 --- /dev/null +++ b/aspnetnew.csproj @@ -0,0 +1,16 @@ + + + + net9.0 + enable + enable + + + + + + + + + + diff --git a/aspnetnew.csproj.user b/aspnetnew.csproj.user new file mode 100644 index 0000000..9ff5820 --- /dev/null +++ b/aspnetnew.csproj.user @@ -0,0 +1,6 @@ + + + + https + + \ No newline at end of file diff --git a/aspnetnew.http b/aspnetnew.http new file mode 100644 index 0000000..5caf46e --- /dev/null +++ b/aspnetnew.http @@ -0,0 +1,6 @@ +@aspnetnew_HostAddress = http://localhost:5167 + +GET {{aspnetnew_HostAddress}}/weatherforecast/ +Accept: application/json + +###