How to schedule a task

Michaël Piel piel at ensm-douai.fr
Thu Mar 16 12:55:49 UTC 2006


Hello Cédric,

On Thu, 16 Mar 2006 12:44:15 +0100
Cédrick Béler <cbeler at enit.fr> 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
> 





More information about the Squeak-dev mailing list