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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

John Logan
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
Reply | Threaded
Open this post in threaded view
|

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

Carsten Ziegeler
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
[hidden email]
Reply | Threaded
Open this post in threaded view
|

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

John Logan
Thanks Carsten, that was my suspicion, just wanted to make sure!

________________________________
From: Carsten Ziegeler <[hidden email]>
Sent: Tuesday, August 7, 2018 11:13:06 PM
To: [hidden email]; 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
[hidden email]