jamesmh / coravel

Near-zero config .NET library that makes advanced application features like Task Scheduling, Caching, Queuing, Event Broadcasting, and more a breeze!
https://docs.coravel.net/Installation/
MIT License
3.91k stars 257 forks source link

Sample to show how to execute Task on demand in .NET core 7 #361

Closed nssidhu closed 2 months ago

nssidhu commented 9 months ago

Describe the solution you'd like I am using Blazor server .NET 7 My requirement is to run the long running process in the background thread. This long running code should only run once and only when user submits the form by clicking the button.

Here is sample of my code.

public class SubmitBackgroundTask : IInvocable { private readonly ILogger _logger; private readonly string _storyID; IDbContextFactory _DbFactory; LexIADBContext _dbContext; public SubmitBackgroundTask(ILogger logger, IDbContextFactory DbFactory, string StoryId) { _DbFactory = DbFactory; _logger = logger; _storyID = StoryId; } public async Task Invoke() { using var _dbContext = await _DbFactory.CreateDbContextAsync(); _logger.LogInformation($"Invocable task running. StoryId is {_storyID}"); await Task.CompletedTask; } } Describe alternatives you've considered I tried to use DI, but i am getting run time error for my second which i cannot provide during registration in program.cs, that userID string parameter is only available when user Click the submit button on index page

jamesmh commented 2 months ago

Using Coravel inside of Blazor doesn't work. See #352 & #369.

Your best case is to use Coravel in a web backend project and have the front end communicate with it via an API, etc.