How to schedule a task

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to schedule a task

cbeler
Hi   :)

I need to get an XML file every three hours from an external website.
For now, I use a wget with a scheduled task... but I was wandering how I
could do that in squeak.
I found Scheduler in squeakmap... would you use that (performance...) ?  
is it better to use wget in case the image crash ?

if you have any comments or idea...

Thank you

Cédrick






--

*/Cédrick/**/ Béler/*



--------------------------------
L'ENIT vous invite a sa journee portes ouvertes le 17 mars 2006 de 13h30 a 19h30

Enit , 47 avenue d'Azereix 65000 Tarbes
 Bus N°1, arret ENI


Reply | Threaded
Open this post in threaded view
|

Re: How to schedule a task

Frank Urbach
Hi Cédrick,

I haven't the whole solution but Bert gave me an advise for such things. Define a method within your class with the task you need with an endless loop. In this loop you wait for the next tick (self waitTick). In this loop you define the loading of the XML file.
Start this method as a script e.g. in the step of initializing.

self startScript: #loadXML

Hope this helps

Cheers,
Frank

-------- Original Message --------
Subject: How to schedule a task (15-Mrz-2006 19:35)
From:    Cédrick Béler <[hidden email]>
To:      [hidden email]

> Hi   :)
>
> I need to get an XML file every three hours from an external website.
> For now, I use a wget with a scheduled task... but I was wandering how I
> could do that in squeak.
> I found Scheduler in squeakmap... would you use that (performance...) ?  
> is it better to use wget in case the image crash ?
>
> if you have any comments or idea...
>
> Thank you
>
> Cédrick
>
>
>
>
>
>
> --
>
> */Cédrick/**/ Béler/*
>
>
>
> --------------------------------
> L'ENIT vous invite a sa journee portes ouvertes le 17 mars 2006 de 13h30 a
> 19h30
>
> Enit , 47 avenue d'Azereix 65000 Tarbes
>  Bus N°1, arret ENI
>



Reply | Threaded
Open this post in threaded view
|

Re: How to schedule a task

Bert Freudenberg-3
However, those scripting extensions do not work in plain Squeak, but  
only in Tweak or Croquet. Also, for a 3 hour delay you might want to  
use a Delay ("self wait: 3*60*60") instead of checking in every tick.  
Or maybe even annotating your method as "<ticking: 0.0001>".

- Bert -

Am 16.03.2006 um 09:07 schrieb Frank Urbach:

> Hi Cédrick,
>
> I haven't the whole solution but Bert gave me an advise for such  
> things. Define a method within your class with the task you need  
> with an endless loop. In this loop you wait for the next tick (self  
> waitTick). In this loop you define the loading of the XML file.
> Start this method as a script e.g. in the step of initializing.
>
> self startScript: #loadXML
>
> Hope this helps
>
> Cheers,
> Frank
>
> -------- Original Message --------
> Subject: How to schedule a task (15-Mrz-2006 19:35)
> From:    Cédrick Béler <[hidden email]>
> To:      [hidden email]
>
>> Hi   :)
>>
>> I need to get an XML file every three hours from an external website.
>> For now, I use a wget with a scheduled task... but I was wandering  
>> how I
>> could do that in squeak.
>> I found Scheduler in squeakmap... would you use that  
>> (performance...) ?
>> is it better to use wget in case the image crash ?
>>
>> if you have any comments or idea...
>>
>> Thank you
>>
>> Cédrick
>>
>



Reply | Threaded
Open this post in threaded view
|

Re: How to schedule a task

cbeler
Hi and thanks for answering :)

> However, those scripting extensions do not work in plain Squeak, but  
> only in Tweak or Croquet.

Thats maybe why I don't have waitTick:    :)

> Also, for a 3 hour delay you might want to  use a Delay ("self wait:
> 3*60*60") instead of checking in every tick.  

Ok for that. When a process is waiting is it consuming ressources ?  is
it reliable ?
If I have well understood, your advice is to use an endless loop instead
of an instance of Scheduler ?

>> I haven't the whole solution but Bert gave me an advise for such  
>> things. Define a method within your class with the task you need  
>> with an endless loop. In this loop you wait for the next tick (self  
>> waitTick). In this loop you define the loading of the XML file.
>> Start this method as a script e.g. in the step of initializing.
>>
>> self startScript: #loadXML
>
I found a method Player>>startScript:   is it the one you're talking about ?

To do in plain squeak, I was thinking doing something like:

Manager class >> initialize
    Smalltalk addToStartUpList: self

Manager class >> startUp  
    self scheduler ifNil: [ self scheduler: TaskScheduler new.
                                        self scheduler
                                                        do:  [self getXML]
                                                        every: 3 hours ].
    self scheduler start.
   
Manager class >> shutDown   " not sure I have too  "
    self scheduler stop

I didnt test it yet
do you think an endless loop (+ wait) is "better" than aScheduler ?
they both seem to use Semaphore (which I dont really understand for
now... need to get into :) )

I have another question concerning #shutDown
Is it called even when the image crashes ?


Thank you

Cédrick























--------------------------------
L'ENIT vous invite a sa journee portes ouvertes le 17 mars 2006 de 13h30 a 19h30

Enit , 47 avenue d'Azereix 65000 Tarbes
 Bus N°1, arret ENI


Reply | Threaded
Open this post in threaded view
|

Re: How to schedule a task

Michaël Piel
Hello Cédric,

On Thu, 16 Mar 2006 12:44:15 +0100
Cédrick Béler <[hidden email]> wrote:

> Hi and thanks for answering :)
>
> > However, those scripting extensions do not work in plain Squeak, but  
> > only in Tweak or Croquet.
>
> Thats maybe why I don't have waitTick:    :)
>
> > Also, for a 3 hour delay you might want to  use a Delay ("self wait:
> > 3*60*60") instead of checking in every tick.  
>
> Ok for that. When a process is waiting is it consuming ressources ?

No, but you may want to execute your process in background if you don't want to have the image locked during the wait of the Delay. So, for example you could do something like:
[self scheduler
    do: [self getXML]
    every: 3 hours]
        forkAt: Processor userBackgroundPriority


> is it reliable ?

Yes, I use it in my developments.

> If I have well understood, your advice is to use an endless loop instead
> of an instance of Scheduler ?
>
> >> I haven't the whole solution but Bert gave me an advise for such  
> >> things. Define a method within your class with the task you need  
> >> with an endless loop. In this loop you wait for the next tick (self  
> >> waitTick). In this loop you define the loading of the XML file.
> >> Start this method as a script e.g. in the step of initializing.
> >>
> >> self startScript: #loadXML
> >
> I found a method Player>>startScript:   is it the one you're talking about ?
>
> To do in plain squeak, I was thinking doing something like:
>
> Manager class >> initialize
>     Smalltalk addToStartUpList: self
>
> Manager class >> startUp  
>     self scheduler ifNil: [ self scheduler: TaskScheduler new.
>                                         self scheduler
>                                                         do:  [self getXML]
>                                                         every: 3 hours ].
>     self scheduler start.
>    
> Manager class >> shutDown   " not sure I have too  "
>     self scheduler stop
>
> I didnt test it yet
> do you think an endless loop (+ wait) is "better" than aScheduler ?
> they both seem to use Semaphore (which I dont really understand for
> now... need to get into :) )
>
> I have another question concerning #shutDown
> Is it called even when the image crashes ?

I don't think.

>
>
> Thank you
>
> Cédrick
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --------------------------------
> L'ENIT vous invite a sa journee portes ouvertes le 17 mars 2006 de 13h30 a 19h30
>
> Enit , 47 avenue d'Azereix 65000 Tarbes
>  Bus N°1, arret ENI
>



Reply | Threaded
Open this post in threaded view
|

Re: How to schedule a task

Bert Freudenberg-3
In reply to this post by cbeler

Am 16.03.2006 um 12:44 schrieb Cédrick Béler:

> Hi and thanks for answering :)
>
>> However, those scripting extensions do not work in plain Squeak,  
>> but  only in Tweak or Croquet.
>
> Thats maybe why I don't have waitTick:    :)
>
>> Also, for a 3 hour delay you might want to  use a Delay ("self  
>> wait: 3*60*60") instead of checking in every tick.
>
> Ok for that. When a process is waiting is it consuming  
> ressources ?  is it reliable ?
> If I have well understood, your advice is to use an endless loop  
> instead of an instance of Scheduler ?
>
>>> I haven't the whole solution but Bert gave me an advise for such  
>>> things. Define a method within your class with the task you need  
>>> with an endless loop. In this loop you wait for the next tick  
>>> (self  waitTick). In this loop you define the loading of the XML  
>>> file.
>>> Start this method as a script e.g. in the step of initializing.
>>>
>>> self startScript: #loadXML
>>
> I found a method Player>>startScript:   is it the one you're  
> talking about ?

No. All of this is specific to Tweak/Croquet.

In normal Squeak you would fork off a block, as described in the  
other replies.

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: How to schedule a task

cdavidshaffer
In reply to this post by cbeler
Seems like you've gotten a fair number of tips but I'd like to add
one...have a look at the KomServices framework.  Subclassing
ApplicationService is pretty straightfoward and gives you a fair amount
of framework support: starting/stopping process on image
startup/shutdown, graceful shutdown (rather than terminating the block),
services registered by name etc.  The class comments will probably tell
you what you need to know but, as an example:

runWhile: aBlock
    [aBlock value]
        whileTrue: [self doSomethingImportant.
            self sleepFor: 30000.]

in a subclass of ApplicationService will execute doSomethingImport every
30 seconds.  You would start it with:

"Start the service"
(MyServiceClass newNamed: 'important service') start


"Stop it"
(MyServiceClass serviceNamed: 'important service') stop.


etc

David


Reply | Threaded
Open this post in threaded view
|

Re: How to schedule a task

cbeler

>Seems like you've gotten a fair number of tips but I'd like to add
>one...
>
no pb   the more I have, the better ;)

Thanks I 'll have a look too

--------------------------------
L'ENIT vous invite a sa journee portes ouvertes le 17 mars 2006 de 13h30 a 19h30

Enit , 47 avenue d'Azereix 65000 Tarbes
 Bus N°1, arret ENI