cancel
Showing results for 
Search instead for 
Did you mean: 

How to terminate Timer job ?

tstephen
Champ on-the-rise
Champ on-the-rise
Hi,

I'm trying to use the Timer start event with an unlimited number of repeats at 1 week intervals (R/P1W). The behaviour I observe in my test case is that the process instance terminates as soon of the first run through the process is complete but the timer continues to exist. Fair enough, each time the timer fires it is creating a new instance in accordance with the BPMN spec.

So how do I remove the timer? I can find the job using the ManagementService but there does not seem to be any way to cancel a job.

How should I be thinking about this?
Tim
9 REPLIES 9

gwaptiva
Champ in-the-making
Champ in-the-making
Single out the Job using the ManagementService's createJobQuery and then cast it to JobEntity and call its delete method.

frederikherema1
Star Contributor
Star Contributor
Calling the delete on the JobEntity will only work when internally when activiti-context is active, so not when calling it through the API…

Currently, nothing is exposed to delete jobs. But doesn't it make more sense, to undeploy the deployment where the timer is defined? This way, you do it the right way I guess…

tstephen
Champ on-the-rise
Champ on-the-rise
I am starting multiple process instances with data, basically I run some periodic tasks for each user. If I undeploy the process def won't all the timers be stopped? In fact I almost certainly only want to stop the timer for a single user.

I also have a problem in my test case since I am deploying using the @Deployment annotation but before this is cleaned up I get a failure because the DB is not 'clean' (having an outstanding Job).

frederikherema1
Star Contributor
Star Contributor
Hmm… can you create a simple unit-test showing this and attach it here? The @Deployment annotation handling will cascade-delete the deployment and check for clean DB after this. So you might be on to a bug, that jobs of a timer start-event aren't deleted when deployment is deleted

tstephen
Champ on-the-rise
Champ on-the-rise
In the course of putting the test case together I found that the Job does not get cleaned up if I extend PluggableActivitiTestCase. However it does work fine if I extend ActivitiTestCase. I'm afraid at this point I don't recall where I got the idea to extend PluggableActivitiTestCase though I suspect it would have been copied from an example somewhere. Both examples are attached here as Eclipse / Maven project if you like to look.

So back to the other part of my question: The usefulness of the timer start would seem to be limited if I can only use it for one data set (in my case one user) because of the need to undeploy the process definition to stop the timer. In the simple example attached I use a service task to periodically 'say hello' to each user where user is process data injected at process start. If one user leaves I appear to have to
- undeploy the template,
- deploy it again (unchanged) and
- start instances for every user except the one who left
Is this really 'the right way'?

I suppose an alternative is to write the process differently and have a task to retrieve the list of users then use a multi-instance service task to 'say hello' to each of them. The reason I originally did not do this is that I would like to vary the interval on the timer for each user.

What do you think, is there a different way to look at this that I am missing?
Tim

jbarrez
Star Contributor
Star Contributor
So, if I understand you correctly you need the managementService.deleteJob(id) method?
I think that's a valid and easy request. Could you create a Jira for this and assign it to me?

tstephen
Champ on-the-rise
Champ on-the-rise
Sounds good Joram. I created http://jira.codehaus.org/browse/ACT-855 but don't seem to be able to assign it to you. Thanks, tim

sudha
Champ in-the-making
Champ in-the-making
can anyone explain how to trigger next task before timer expired. Basically i need to cancel the timer and trigger the next task. When i complete the timer it is not triggering the next task.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Sudha.

some of possibilities:
-> change timer's due date,
-> change process engine time.

Regards
Martin