Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to cehck is job running or not? #257

Closed
Aleksej-Shherbak opened this issue Oct 2, 2019 · 3 comments
Closed

How to cehck is job running or not? #257

Aleksej-Shherbak opened this issue Oct 2, 2019 · 3 comments

Comments

@Aleksej-Shherbak
Copy link

Aleksej-Shherbak commented Oct 2, 2019

How to cehck is job running or not? 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 not. How I can do this? I can't see the suitable method.

@insanity13
Copy link

insanity13 commented Oct 4, 2019

As an option, you can Subscribe to Jobs Event and keep a list of running tasks manually.

JobManager.JobStart

JobManager.JobEnd

JobManager.JobException

@Aleksej-Shherbak
Copy link
Author

So, after some tests I have understood that I can't stop or start particular job. Instead, I can remove or add job via JobManager.Stop() or JobManager.Start().

So here is the code.

Start and stop:

public IActionResult StopSender()
{
    JobManager.RemoveJob("push_distribution");
    
    return RedirectToAction("Index");
}

public IActionResult StartSender()
{
    JobManager.RemoveJob("push_distribution");

    var registry = new Registry();
    registry.Schedule<SendPushesJob>().WithName("push_distribution").ToRunNow().AndEvery(60).Seconds();

    JobManager.Initialize(registry);

    return RedirectToAction("Index");
}

Show if the job is running:

<span>
    @if (JobManager.AllSchedules.Any(x => x.Name == "push_distribution"))
    {
        <strong class="text-success">Working!</strong>   
    }
    else
    {
        <strong>Not working!</strong>   
    }
</span>

Is it correct way?

@tallesl
Copy link
Contributor

tallesl commented Aug 2, 2020

That seems to be correct. It's embarrassingly cumbersome doing that in the current version, and it shouldn't.

We'll be fixing that on 6.0.0, see #273.

@tallesl tallesl closed this as completed Aug 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants