ScheduledFutures and Cancelling?

24 views
Skip to first unread message

Bryan Stopp

unread,
Apr 26, 2021, 11:04:55 PM4/26/21
to Jenkins Developers

When writing a custom step that creates a scheduled task, are you responsible for calling the "cancel()" method before/after you call "onSuccess/onFailure"

I'm getting an error:

completed: already completed CpsStepContext

after my timer has called the onSuccess method, so I assume i'm not doing things in the correct order.

Is there a good example of the proper methodology for this? The only example i can find is the WaitConditionStep - but that calls a body with callback, and so it sets up a net-new timer w/ new runnable instance; not a repeated call of the same Runnable.

Right now with this error i'm guessing i should do, these steps always in this order:

onSuccess/onFailure (depending on state)
task.cancel(true);
task = null;
return;

Am i wrong or missing something?

Thanks in advance!

-Bryan

Jesse Glick

unread,
Apr 27, 2021, 10:44:37 AM4/27/21
to Jenkins Dev
On Mon, Apr 26, 2021 at 11:04 PM Bryan Stopp <bryan...@gmail.com> wrote:
I'm getting an error:

completed: already completed CpsStepContext

after my timer has called the onSuccess method

Somehow you are calling `onSuccess` and/or `onFailure` two or more times, which is illegal. The warning is not fatal (subsequent calls are ignored) but may be indicative of a real bug. 

Bryan Stopp

unread,
Apr 27, 2021, 11:16:55 AM4/27/21
to jenkin...@googlegroups.com
Right - My timer never stopped. So my question is: who's responsible for calling "cancel()" on the timer? I assume I am.. but i'm not sure if this is really a "good practice". My current implementation is here:


Grateful for any pointers and/or criticism.

Thanks!

-B

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/TpUAft3fSxE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1gK-7kdteh6-uJfWWQbqf%2B2s-tL-9LpwChGEa5fBVZ5w%40mail.gmail.com.

Jesse Glick

unread,
Apr 27, 2021, 11:28:10 AM4/27/21
to Jenkins Dev
On Tue, Apr 27, 2021 at 11:16 AM Bryan Stopp <bryan...@gmail.com> wrote:
who's responsible for calling "cancel()" on the timer?

If you started a recurrent timer, then you are responsible for cancelling it eventually. Nothing to do with Pipeline.

I would normally write this idiom by using plain `schedule` and then inside the block calling `schedule` again if the goal was not realized as expected, but I suppose it amounts to the same thing.
Reply all
Reply to author
Forward
0 new messages