You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by John Logan <Jo...@texture.com> on 2018/08/07 20:31:08 UTC

Can I detect cancellation of an active Sling job to facilitate cleanup?

Hi, in our Sling application we create jobs for long-running tasks using the JobManager service, and in those jobs, subtasks are scheduled to a separate compute grid.


What I was curious about was whether there was any way to asynchronously detect and perform cleanup when a job is stopped by the user via jobManager.stopJobById().  Or is it that the only way to handle this is to intersperse checks for the job STOPPED state throughout logic that I've implemented under the process() method of each JobConsumer that I've implemented?


From the documentation and codte, it looks like I have to do the latter, but I thought I'd check as if the former were possible it might simplify the job cancellation processing, and it would allow canceled jobs to be cleaned up more quickly.


Thank you!


John Logan

Re: Can I detect cancellation of an active Sling job to facilitate cleanup?

Posted by John Logan <Jo...@texture.com>.
Thanks Carsten, that was my suspicion, just wanted to make sure!

________________________________
From: Carsten Ziegeler <cz...@apache.org>
Sent: Tuesday, August 7, 2018 11:13:06 PM
To: users@sling.apache.org; John Logan
Subject: Re: Can I detect cancellation of an active Sling job to facilitate cleanup?

Hi,

yes, it is the second option, your code needs to check frequently
whether it got stopped. This is mostly due to the fact that there is no
good way in java to stop a thread.

Regards

Carsten


John Logan wrote
> Hi, in our Sling application we create jobs for long-running tasks using the JobManager service, and in those jobs, subtasks are scheduled to a separate compute grid.
>
>
> What I was curious about was whether there was any way to asynchronously detect and perform cleanup when a job is stopped by the user via jobManager.stopJobById().  Or is it that the only way to handle this is to intersperse checks for the job STOPPED state throughout logic that I've implemented under the process() method of each JobConsumer that I've implemented?
>
>
> From the documentation and codte, it looks like I have to do the latter, but I thought I'd check as if the former were possible it might simplify the job cancellation processing, and it would allow canceled jobs to be cleaned up more quickly.
>
>
> Thank you!
>
>
> John Logan
>
--
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org

Re: Can I detect cancellation of an active Sling job to facilitate cleanup?

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi,

yes, it is the second option, your code needs to check frequently
whether it got stopped. This is mostly due to the fact that there is no
good way in java to stop a thread.

Regards

Carsten


John Logan wrote
> Hi, in our Sling application we create jobs for long-running tasks using the JobManager service, and in those jobs, subtasks are scheduled to a separate compute grid.
> 
> 
> What I was curious about was whether there was any way to asynchronously detect and perform cleanup when a job is stopped by the user via jobManager.stopJobById().  Or is it that the only way to handle this is to intersperse checks for the job STOPPED state throughout logic that I've implemented under the process() method of each JobConsumer that I've implemented?
> 
> 
> From the documentation and codte, it looks like I have to do the latter, but I thought I'd check as if the former were possible it might simplify the job cancellation processing, and it would allow canceled jobs to be cleaned up more quickly.
> 
> 
> Thank you!
> 
> 
> John Logan
> 
-- 
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org