dotnet-labs/ServiceWorkerCronJob

How to manually start/stop jobs

amyrprv opened this issue · 1 comments

How I can have control over jobs and manually start/stop themes?

I utilize the Service and make an API endpoint so that the front end can trigger the process defined in my Service class. I haven't tried to stop the process when it is running. But you probably can try to pass a cancellation token to the process.

The service I referred to is like the one below.

using var scope = _serviceProvider.CreateScope();
var svc = scope.ServiceProvider.GetRequiredService<IMyScopedService>();
await svc.DoWork(cancellationToken);

In the CronJob class, you call the service to do work. You can do the same thing in your controller, and you don't need to initiate a scope in the controller. Then admins can click a button in a web page to run the job on demand.