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

[Feature Request] Document host builder caveats #220

Closed
cretz opened this issue Apr 15, 2024 · 0 comments · Fixed by #230
Closed

[Feature Request] Document host builder caveats #220

cretz opened this issue Apr 15, 2024 · 0 comments · Fixed by #230
Labels
enhancement New feature or request

Comments

@cretz
Copy link
Member

cretz commented Apr 15, 2024

Describe the solution you'd like

Look at this snippet:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Temporalio.Client;
using Temporalio.Extensions.Hosting;
using Temporalio.Worker;
using Temporalio.Workflows;

async Task RunAsync()
{
    // Start workflow
    var client = await TemporalClient.ConnectAsync(new("localhost:7233"));
    await client.StartWorkflowAsync(
        (MyWorkflow wf) => wf.RunAsync(),
        new(id: $"wf-{Guid.NewGuid()}", "my-task-queue"));

    // Run worker (change to false and this will start working)
    const bool useHostBuilder = true;
    try
    {
        if (useHostBuilder)
        {
            var builder = Host.CreateApplicationBuilder();
            builder.Services.AddHostedTemporalWorker("localhost:7233", "default", "my-task-queue").AddWorkflow<MyWorkflow>();
            var host = builder.Build();
            // Change next line to "await host.RunAsync();" and it will start working
            host.Run();
        }
        else
        {
            var worker = new TemporalWorker(
                client, new TemporalWorkerOptions("my-task-queue").AddWorkflow<MyWorkflow>());
            await worker.ExecuteAsync(default);
        }
    }
    catch (OperationCanceledException)
    {
        Console.WriteLine("Workers cancelled");
    }
}

await RunAsync();

[Workflow]
public class MyWorkflow
{
    [WorkflowRun]
    public Task<string> RunAsync() => Task.FromResult("done");
}

It doesn't poll, but if you change host.Run() to host.RunAsync() it works. Very strange. So document that in the Temporalio.Extensions.Hosting README. Also document the caveat about issue 36063 in https://github.com/dotnet/runtime (not linking by intention) which trips people up and is a known issue.

@cretz cretz added the enhancement New feature or request label Apr 15, 2024
@cretz cretz changed the title [Feature Request] Document host.Run vs host.RunAsync caveat [Feature Request] Document host builder caveats Apr 15, 2024
cretz added a commit to cretz/temporal-sdk-dotnet that referenced this issue Apr 24, 2024
@cretz cretz mentioned this issue Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant