[Cubicweb] Set up a looping task in cubicweb

Adrien Di Mascio adrien.dimascio at logilab.fr
Sun Dec 13 16:45:55 CET 2009


Hi Florent,

Le Sat, 12 Dec 2009 22:49:46 +0100, Florent Cayré <florent at secondweb.fr> a  
écrit:

> I've just seen the looping_task repo method but just do not know how to  
> use
> it: the docstring mentions "looping tasks can only be registered during
> repository initialization, once done this method will fail.", so I  
> suppose
> there is a hook dedicated to this kind of initialization. Any example
> someone ?

You'll find an example in the apycot cube. The event you're looking for is
'server_startup'. Here's a simple example showing the basic idea :


class ServerStartupHook(hooksmanager.Hook):
     events = ('server_startup',)

     def call(self, repo):
         def the_looping_task(repo):
             session = repo.internal_session()
             # now, you can do something with session here.
         repo.looping_task(60*60*24,         # the interval in seconds
                           the_looping_task, # the callback
                           # additional args will be passed to the callback
                           repo)



Regards,
-- 
Adrien Di Mascio                              LOGILAB, Paris (France).
Formations Python,Zope,Debian,Calcul    http://www.logilab.fr/formations
Informatique scientifique:              http://www.logilab.fr/science
Gestion de connaissances:               http://www.cubicweb.org/



More information about the Cubicweb mailing list