You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Andreas Hartmann <an...@apache.org> on 2005/03/11 15:35:18 UTC

[cron block] Execute job with original request setup

Hi Cocoon devs,

in the process of moving the Lenya scheduler to Cocoon components,
I played a little bit with the cron block.

At first I tried to invoke a Lenya service from the scheduler by
obtaining the service directly via the ServiceableJob's service manager.
But this way I ended up with exceptions, because the request URI
was empty. Originally, the service was only invoked from the web
interface via flowscript.

Some questions:

1) Is it possible to initialize a cron job with the original environment
    information?

2) Or is it unwise to implement Contextualizable and access the request
    object via the ContextHelper in services which can be called from
    the scheduler? If yes, would that mean I should pass the request
    URI etc. manually?

3) Are there any general hints how to implement such a behaviour
    (call the same service from web interface and scheduler)?

Thanks in advance!

-- Andreas


Re: [cron block] Execute job with original request setup

Posted by Andreas Hartmann <an...@apache.org>.
Pierre Martins wrote:
> Hi Andreas,

[...]

Thanks for your help!
I managed to make it work.

-- Andreas


Re: [cron block] Execute job with original request setup

Posted by Pierre Martins <pi...@symeria.com>.
Hi Andreas,

I saw Vadim already gave you some infos.
I am using directly the Quartz Scheduler Agent from Cocoon aand don't 
know much more about Lenya.
Nevertheless, the mechanism should be the same.
 
Andreas Hartmann wrote:

> Hi Cocoon devs,
>
> in the process of moving the Lenya scheduler to Cocoon components,
> I played a little bit with the cron block.
>
> At first I tried to invoke a Lenya service from the scheduler by
> obtaining the service directly via the ServiceableJob's service manager.
> But this way I ended up with exceptions, because the request URI
> was empty. Originally, the service was only invoked from the web
> interface via flowscript.
>
> Some questions:
>
> 1) Is it possible to initialize a cron job with the original environment
>    information?

I would look directly on the cocoon.xconf file.
I looked quickly and it looks like Lenya is using the Quartz scheduler 
from Cocoon.
A a consequence, you should be able to initialize your cron job directly 
in the cocoon.xconf by providing the correct parameters.
This will be ok only if you have a predefine number of tasks to load.

>
> 2) Or is it unwise to implement Contextualizable and access the request
>    object via the ContextHelper in services which can be called from
>    the scheduler? If yes, would that mean I should pass the request
>    URI etc. manually?
>
Personally I modified the QuartzScheduler so that it can read into a DB 
when starting Cocoon.
This way all the cron Job I have already configured are automatically 
loaded and the correct parameters.
It enables me to create or remove tasks during my session. Those 
modification will reamins when cocoon restarts
I think your Idea with the ContextHelper might be fine but you need to 
find a way to provide the correct info to it.

> 3) Are there any general hints how to implement such a behaviour
>    (call the same service from web interface and scheduler)?

Refer to my first answer. Again, I am using the QuartzScheduler directly 
but this system allows me to define my tasks through a URI, when Cocoon 
restart they are all loaded.

>
> Thanks in advance!
>
> -- Andreas
>
I hope this will help, sorry if I missed something,
Pierre

>
>


Re: [cron block] Execute job with original request setup

Posted by Andreas Hartmann <an...@apache.org>.
Vadim Gritsenko wrote:
> Andreas Hartmann wrote:
> 
>> Hi Cocoon devs,
>>
>> in the process of moving the Lenya scheduler to Cocoon components,
>> I played a little bit with the cron block.
>>
>> At first I tried to invoke a Lenya service from the scheduler by
>> obtaining the service directly via the ServiceableJob's service manager.
>> But this way I ended up with exceptions, because the request URI
>> was empty. Originally, the service was only invoked from the web
>> interface via flowscript.
>>
>> Some questions:
>>
>> 1) Is it possible to initialize a cron job with the original environment
>>    information?
> 
> 
> What's "original environment" in the context of a cron job? There is no 
> environment there, only service manager.

I had to adjust my viewpoint a little and changed the way the cron job
works. The original URL (of the request which created and scheduled the
job) is stored in the job and passed to all services which depend on the
URL.


>> 2) Or is it unwise to implement Contextualizable and access the request
>>    object via the ContextHelper in services which can be called from
>>    the scheduler? If yes, would that mean I should pass the request
>>    URI etc. manually?
> 
> 
> What is "URI" for a cron task?

I meant the original URL if the request which led to the scheduling
of the cron job. A typical example is a publishing Job in Lenya. The
URL is used to determine the document to be published.


> You can think in terms of unix cron, if 
> it is helps.
> 
> Probably ConfigurableCronJob is what you need - so that you can pass 
> parameters into the job.

That was exactly what I needed. Thank you very much.

-- Andreas


Re: [cron block] Execute job with original request setup

Posted by Vadim Gritsenko <va...@reverycodes.com>.
Andreas Hartmann wrote:
> Hi Cocoon devs,
> 
> in the process of moving the Lenya scheduler to Cocoon components,
> I played a little bit with the cron block.
> 
> At first I tried to invoke a Lenya service from the scheduler by
> obtaining the service directly via the ServiceableJob's service manager.
> But this way I ended up with exceptions, because the request URI
> was empty. Originally, the service was only invoked from the web
> interface via flowscript.
> 
> Some questions:
> 
> 1) Is it possible to initialize a cron job with the original environment
>    information?

What's "original environment" in the context of a cron job? There is no 
environment there, only service manager.


> 2) Or is it unwise to implement Contextualizable and access the request
>    object via the ContextHelper in services which can be called from
>    the scheduler? If yes, would that mean I should pass the request
>    URI etc. manually?

What is "URI" for a cron task? You can think in terms of unix cron, if it is helps.

Probably ConfigurableCronJob is what you need - so that you can pass parameters 
into the job. Or, you can take a look at the CocoonPipelineCronJob which 
*creates* new background environment and invokes particular pipeline - so in 
this case you'll have the request with URI as created by the cron job.

Vadim


> 3) Are there any general hints how to implement such a behaviour
>    (call the same service from web interface and scheduler)?
> 
> Thanks in advance!
> 
> -- Andreas