Exemplo n.º 1
0
 def run( self ):
     while self.state != "Stopping" :
         try:
             self.state = "Ready"
             m = self.queue.get( timeout=self.task._timeout )
             if not hasattr( self.task._state, m.name ):
                 syslog( "%s does not have %s" % ( self.task._state, m.name ))
                 self.task._state.not_implemented( m.name )
                 continue
             func = getattr( self.task._state, m.name )
             self.state = "Working"
             # print 'from %s, doing: %s' % ( m.task, func )
             try:
                 m.future.set_value( func( *m.args, **m.kwds ))
             except:
                 syslog( 'Exception: %s %s' % ( m.name, sys.exc_info( )[1]))
                 self.manager.log( self.task, "funccall %s failed: %s (%s)" % ( m.name, sys.exc_info( )[1], traceback.format_exc( ) ))
                 self.task._state.exception( m.name )
         except Empty :
             if self.state == "Ready" :
                 try:
                     self.task._state.timeout( )
                 except:
                     self.manager.log( self.task, "timeout %s failed: %s (%s)" % ( m.name, sys.exc_info( )[1], traceback.format_exc( ) ))
                     self.task._state.exception( m.name )
     self.state = "Stopped"
Exemplo n.º 2
0
 def confModules( self ):
     self.state = "Configuration"
     prio = 0
     while prio < self.prio :
         for name, module in self.modules.items( ) :
             if module.prio == prio :
                 filename = 'conf/%s.py' % self.env
                 if os.access(filename, os.R_OK ):
                     f = open(filename)
                     code = compile(f.read(), filename, 'exec')
                     exec(code, { 'task' : module.task })
                     # execfile( 'conf/%s.py' % self.env, { 'task' : module.task })
                 if module.conf :
                     if os.access( module.conf, os.R_OK ):
                         f = open(module.conf)
                         code = compile(f.read(), module.conf, 'exec')
                         exec(code, { 'task' : module.task })
                     else:
                         syslog( 'Warning: %s could not be read' % module.conf )
                 module.task.conf( )
         prio += 1
     self.state = "Configured"