elsa-core/samples/Elsa.Samples.AspNet.HangfireIntegration/Jobs/SomeJob.cs
Sipke Schoorstra a397b6799e Add new sample project for ASP.NET Hangfire Integration
Introduced a new sample project to demonstrate ASP.NET integration with Hangfire, including setup configurations in `appsettings.json`, program initialization, and a background job activity. This will serve as a reference implementation for integrating Elsa with Hangfire in ASP.NET applications.
2024-11-04 11:59:47 +01:00

34 lines
1.1 KiB
C#

using Elsa.Samples.AspNet.HangfireIntegration.Models;
using Elsa.Workflows.Runtime;
using Elsa.Workflows.Runtime.Filters;
using Elsa.Workflows.Runtime.Options;
namespace Elsa.Samples.AspNet.HangfireIntegration.Jobs;
public class SomeJob(IBookmarkResumer bookmarkResumer)
{
public async Task RunAsync(string bookmarkId, CancellationToken cancellationToken)
{
Console.Write("Executing some job...");
await Task.Delay(5000, cancellationToken);
Console.WriteLine("Done!");
await ResumeBookmarkAsync(bookmarkId, cancellationToken);
}
private async Task ResumeBookmarkAsync(string bookmarkId, CancellationToken cancellationToken)
{
var resumeOptions = new ResumeBookmarkOptions
{
Input = new Dictionary<string, object>
{
["JobResult"] = new SomeJobResult { Message = "Hello from SomeJob!" }
}
};
var filter = new BookmarkFilter
{
BookmarkId = bookmarkId
};
await bookmarkResumer.ResumeAsync(filter, resumeOptions, cancellationToken);
}
}