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.92k stars 257 forks source link

How to stop / clear all tasks? #408

Open fatihyildizhan opened 2 months ago

fatihyildizhan commented 2 months ago

Hello,

I was trying and created multiple tasks and couldn't stop them.

I want to stop all of them. Is there a way to do this?

Thank you very much for your time

Tried these: 1) https://github.com/jamesmh/coravel/issues/371 2) https://github.com/jamesmh/coravel/discussions/385 3) https://github.com/jamesmh/coravel/issues/216

fatihyildizhan commented 1 month ago

Hello,

When I make changes to Task1 or Task2 and send it to the server, sometimes it starts working more than once.

For example, 3 Task1s start working EveryTenMinutes on the server.

How can I delete all the existing Tasks before scheduling?

Thank you for your time.

public class Task1 : IInvocable
{
    public async Task Invoke()
    {
        // do something
    }
}
app.Services.UseScheduler(scheduler =>
{
    scheduler.OnWorker("Task1Worker");
    scheduler.Schedule<Task1>()
    .EveryTenMinutes()
    .RunOnceAtStart()
    .PreventOverlapping("Task1");

    scheduler.OnWorker("Task2Worker");
    scheduler.Schedule<Task2>()
    .EveryTenMinutes()
    .RunOnceAtStart()
    .PreventOverlapping("Task2");
})
.OnError((exception) =>
    Console.WriteLine(exception.ToString())
);
jamesmh commented 1 month ago

There is no API to clear the scheduler.

If you really need this, you could attach and id to every job you've scheduled (see here) and then unschedule all of the jobs manually.