[Cubicweb] Set up a looping task in cubicweb

Sylvain Thénault sylvain.thenault at logilab.fr
Mon Dec 14 08:55:01 CET 2009


On 13 décembre 16:45, Adrien Di Mascio wrote:
> 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()

              try:
                   XXX
              finally:
                  # cw sensible to session leak...
                  session.close()

>             # 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/
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/cubicweb
> 

-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org




More information about the Cubicweb mailing list