You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Kl...@ethalon.de on 2012/11/26 14:36:56 UTC

How to avoid starting a route multiple times?

Hello Camel experts
I have a scheduled route that runs every few minutes to do some background 
work. If for whatever reason the route takes longer than expected, the 
schedule may start another execution of the route.
Is there an easy way to say that the route is not started again, if it is 
still running?

Thanks
Klaus



Re: How to avoid starting a route multiple times?

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Nov 26, 2012 at 5:26 PM, klauss42 <kl...@ethalon.de> wrote:
> I use the Quartz component:
>
> <camel:route>
>         <camel:from uri="quartz://mailSender/0?cron=0,30+*+*+*+*+?" />
>         ....
> </camel:route>
>
> This route runs every 30 seconds which is the desired behavior.
>

Ah yeah I guess thats the current correct behavior. I think what would
be needed is to add new functionality to camel-quartz, to allow you to
configure an option to limit number of current jobs.

I assume we can use the Quartz API to query it if the mailSender job
is currently running or not. And then just avoid triggering the route
if a limit is reached.

Maybe if you have the time, could look into this?


> Klaus
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-avoid-starting-a-route-multiple-times-tp5723236p5723248.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: How to avoid starting a route multiple times?

Posted by klauss42 <kl...@ethalon.de>.
I use the Quartz component: 

<camel:route>
	<camel:from uri="quartz://mailSender/0?cron=0,30+*+*+*+*+?" />
	....
</camel:route>

This route runs every 30 seconds which is the desired behavior. 

Klaus



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-avoid-starting-a-route-multiple-times-tp5723236p5723248.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to avoid starting a route multiple times?

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Nov 26, 2012 at 2:36 PM,  <Kl...@ethalon.de> wrote:
> Hello Camel experts
> I have a scheduled route that runs every few minutes to do some background
> work. If for whatever reason the route takes longer than expected, the
> schedule may start another execution of the route.
> Is there an easy way to say that the route is not started again, if it is
> still running?
>

How do you schedule the routes to run?


> Thanks
> Klaus
>
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: How to avoid starting a route multiple times?

Posted by tamil13 <ta...@gmail.com>.
use if condition.



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-avoid-starting-a-route-multiple-times-tp5723236p5723238.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to avoid starting a route multiple times?

Posted by klauss42 <kl...@ethalon.de>.
Hi again
I just tried "stateful" in my quartz component and it looks fine so far. For
the test I made my route running longer than the schedule interval (using
Thread.sleep()) and the next execution of the route is then delayed, as
described in the quartz docs:

/... The other difference is that stateful jobs are not allowed to execute
concurrently, which means new triggers that occur before the completion of
the execute(xx) method will be delayed.
/

So the result is, that I simply add "stateful=true" to the quartz URI of my
routes and then quartz ensures, that the job is not executed concurrently.

<camel:route>
	<camel:from
uri="quartz://mailSender/1?stateful=true&amp;cron=0+0+7,13+*+*+?" />
	<camel:process ref="mailReader" />
  ...
</camel:route>



Thanks
Klaus



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-avoid-starting-a-route-multiple-times-tp5723236p5723304.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to avoid starting a route multiple times?

Posted by klauss42 <kl...@ethalon.de>.
Claus Ibsen-2 wrote
> On Tue, Nov 27, 2012 at 11:15 AM, Babak Vahdat
> &lt;

> babak.vahdat@

> &gt; wrote:
>> Hi
>>
>> I'm not a Quartz expert but think (if I understand your question
>> correctly)
>> you could make use of the "stateful" option in your URI:
>>
>> http://camel.apache.org/quartz
>>
>> And then according what the Javadoc says, the required behaviour should
>> be
>> already given for free (new triggers that occur before the completion of
>> the
>> execute(xx) method will be delayed):
>>
>> http://quartz-scheduler.org/api/1.8.5/org/quartz/StatefulJob.html
>>
>> Does my rambling make sense at all?
>>
> 
> Yeah this seems like the solution.
> 
> If it works for you. Then we could possible improve the camel-quartz
> docs with some better details about this.
> 
>> Babak
>>
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/How-to-avoid-starting-a-route-multiple-times-tp5723236p5723296.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> FuseSource is now part of Red Hat
> Email: 

> cibsen@

> Web: http://fusesource.com
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen

Thanks for the answers, I will try it with "stateful".

Klaus 



--
View this message in context: http://camel.465427.n5.nabble.com/How-to-avoid-starting-a-route-multiple-times-tp5723236p5723301.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: How to avoid starting a route multiple times?

Posted by Claus Ibsen <cl...@gmail.com>.
On Tue, Nov 27, 2012 at 11:15 AM, Babak Vahdat
<ba...@swissonline.ch> wrote:
> Hi
>
> I'm not a Quartz expert but think (if I understand your question correctly)
> you could make use of the "stateful" option in your URI:
>
> http://camel.apache.org/quartz
>
> And then according what the Javadoc says, the required behaviour should be
> already given for free (new triggers that occur before the completion of the
> execute(xx) method will be delayed):
>
> http://quartz-scheduler.org/api/1.8.5/org/quartz/StatefulJob.html
>
> Does my rambling make sense at all?
>

Yeah this seems like the solution.

If it works for you. Then we could possible improve the camel-quartz
docs with some better details about this.

> Babak
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/How-to-avoid-starting-a-route-multiple-times-tp5723236p5723296.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: How to avoid starting a route multiple times?

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

I'm not a Quartz expert but think (if I understand your question correctly)
you could make use of the "stateful" option in your URI:

http://camel.apache.org/quartz

And then according what the Javadoc says, the required behaviour should be
already given for free (new triggers that occur before the completion of the
execute(xx) method will be delayed):

http://quartz-scheduler.org/api/1.8.5/org/quartz/StatefulJob.html

Does my rambling make sense at all?

Babak





--
View this message in context: http://camel.465427.n5.nabble.com/How-to-avoid-starting-a-route-multiple-times-tp5723236p5723296.html
Sent from the Camel - Users mailing list archive at Nabble.com.