0

How to check if job running for FluentScheduler .NET. I have the following code in the Startup.cs class for initializing my job:

var registry = new Registry();
registry.Schedule<SendPushesJob>().ToRunNow().AndEvery(60).Seconds();
JobManager.Initialize(registry);

and the following code in my controller:

public IActionResult StopSender()
{
    JobManager.Stop();

    return RedirectToAction("Index");
}

public IActionResult StartSender()
{
    JobManager.Start();

    return RedirectToAction("Index");
}

I would like to show on the view is my job started or stopped. How I can do this? I can't see the suitable method.

Aleksej_Shherbak
  • 2,757
  • 5
  • 34
  • 71
  • 1
    [Source code](https://github.com/fluentscheduler/FluentScheduler/blob/master/Library/JobManager.cs#L240) shows a `JobManager.RunningSchedules()` that returns *Collection of the currently running schedules* – Nkosi Oct 02 '19 at 17:27
  • 1
    There is also the option to get the desired schedule and check its status – Nkosi Oct 02 '19 at 17:29

1 Answers1

0

Maybe this is not very elegant way but I have solved it with the following way.

In my controller:

public IActionResult StopSender()
{
    JobManager.RemoveAllJobs();

    return RedirectToAction("Index");
}

public IActionResult StartSender()
{
    var registry = new Registry();
    registry.Schedule<SendPushesJob>().ToRunNow().AndEvery(60).Seconds();
    JobManager.Initialize(registry);

    return RedirectToAction("Index");
}

In the view:

<span>
    @if (JobManager.AllSchedules.Any())
    {
        <strong class="text-success">Scheduler is working!</strong>   
    }
    else
    {
        <strong>Scheduler is stopped</strong>   
    }
</span>

I think you understand that I have only one job in my project.

Aleksej_Shherbak
  • 2,757
  • 5
  • 34
  • 71