Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 15 additions & 24 deletions AspNetCore/React/AdvancedSearch/Controllers/SampleDataController.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Temporalio.Client;
using EqDemo.Workflows;

namespace EqDemo.Controllers
{
[Route("api/[controller]")]
public class SampleDataController : Controller
{
private static string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ITemporalClient _temporalClient;

[HttpGet("[action]")]
public IEnumerable<WeatherForecast> WeatherForecasts()
public SampleDataController(ITemporalClient temporalClient)
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
DateFormatted = DateTime.Now.AddDays(index).ToString("d"),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
});
_temporalClient = temporalClient;
}

public class WeatherForecast
[HttpGet("[action]")]
public async Task<IEnumerable<WeatherActivities.WeatherForecast>> WeatherForecasts()
{
public string DateFormatted { get; set; }
public int TemperatureC { get; set; }
public string Summary { get; set; }
var handle = await _temporalClient.StartWorkflowAsync(
(WeatherWorkflow wf) => wf.RunAsync(),
new WorkflowOptions
{
Id = $"weather-forecast-{Guid.NewGuid()}",
TaskQueue = "advanced-search-task-queue"
});

public int TemperatureF
{
get {
return 32 + (int)(TemperatureC / 0.5556);
}
}
return await handle.GetResultAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="6.34.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
<PackageReference Include="Temporalio" Version="1.5.0" />
<PackageReference Include="Temporalio.Extensions.Hosting" Version="1.5.0" />
</ItemGroup>
<ItemGroup>
<!-- DB initialization packages. They are not necessary for EasyQuery working and can be removed in production -->
Expand Down
11 changes: 11 additions & 0 deletions AspNetCore/React/AdvancedSearch/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

using Korzh.EasyQuery.Services;
using EasyData.Export;
using Temporalio.Extensions.Hosting;
using EqDemo.Workflows;

namespace EqDemo
{
Expand Down Expand Up @@ -49,6 +51,15 @@ public void ConfigureServices(IServiceCollection services)
configuration.RootPath = "ClientApp/build";
});

services.AddTemporalClient(clientOptions => {
clientOptions.TargetHost = Configuration.GetValue<string>("Temporal:TargetHost") ?? "localhost:7233";
clientOptions.Namespace = Configuration.GetValue<string>("Temporal:Namespace") ?? "default";
});

services.AddHostedTemporalWorker("advanced-search-task-queue")
.AddScopedActivities<WeatherActivities>()
.AddWorkflow<WeatherWorkflow>();

services.AddEasyQuery()
.UseSqlManager()
.AddDefaultExporters()
Expand Down
31 changes: 31 additions & 0 deletions AspNetCore/React/AdvancedSearch/Workflows/WeatherActivities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Temporalio.Activities;

namespace EqDemo.Workflows;

public class WeatherActivities
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

[Activity]
public List<WeatherForecast> GetWeatherForecasts()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
DateFormatted = DateTime.Now.AddDays(index).ToString("d"),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
}).ToList();
}

public class WeatherForecast
{
public string DateFormatted { get; set; }
public int TemperatureC { get; set; }
public string Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
16 changes: 16 additions & 0 deletions AspNetCore/React/AdvancedSearch/Workflows/WeatherWorkflow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Temporalio.Workflows;

namespace EqDemo.Workflows;

[Workflow]
public class WeatherWorkflow
{
[WorkflowRun]
public async Task<List<WeatherActivities.WeatherForecast>> RunAsync()
{
return await Workflow.ExecuteActivityAsync(
(WeatherActivities act) => act.GetWeatherForecasts(),
new ActivityOptions { StartToCloseTimeout = TimeSpan.FromSeconds(30) }
);
}
}
12 changes: 12 additions & 0 deletions AspNetCore/React/AdvancedSearch/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.8'
services:
temporal:
image: temporalio/auto-setup:latest
ports:
- "7233:7233"
temporal-ui:
image: temporalio/ui:latest
ports:
- "8080:8080"
environment:
- TEMPORAL_ADDRESS=temporal:7233