Ejemplo n.º 1
0
 def handle(self, speed, argslist):
     """ schedule a job. """
     self.working = True
     try:
         try:
             descr, func, args, kwargs = argslist
         except ValueError:
             try:
                 descr, func, args = argslist
                 kwargs = {}
             except ValueError:
                 descr, func = argslist
                 args = ()
                 kwargs = {}
         self.nowrunning = getname(func) + " - " + descr
         logging.info('running %s - %s- %s' % (descr, str(func), args))
         self.starttime = time.time()
         result = func(*args, **kwargs)
         self.finished = time.time()
         self.elapsed = self.finished - self.starttime
         if self.elapsed > 5:
             logging.debug('ALERT %s %s job taking too long: %s seconds' %
                           (descr, str(func), self.elapsed))
         stats.upitem(self.nowrunning)
         stats.upitem(self.name)
         logstr = "finished %s - %s (%s)" % (self.nowrunning, result
                                             or "no result", self.elapsed)
         logging.warn(logstr)
         time.sleep(0.005)
     except Exception, ex:
         handle_exception()
         result = str(ex)
Ejemplo n.º 2
0
 def handle(self, speed, argslist):
     """ schedule a job. """
     self.working = True
     try:
         try: descr, func, args, kwargs = argslist
         except ValueError:
             try:
                 descr, func, args = argslist
                 kwargs = {}
             except ValueError:
                 descr, func = argslist
                 args = ()
                 kwargs = {}                  
         self.nowrunning = getname(func) + " - " + descr 
         logging.info('running %s - %s- %s' % (descr, str(func), args))
         self.starttime = time.time()
         result = func(*args, **kwargs)
         self.finished = time.time()
         self.elapsed = self.finished - self.starttime
         if self.elapsed > 5:
             logging.debug('ALERT %s %s job taking too long: %s seconds' % (descr, str(func), self.elapsed))
         stats.upitem(self.nowrunning)
         stats.upitem(self.name)
         logstr = "finished %s - %s (%s)" % (self.nowrunning, result or "no result", self.elapsed)
         logging.warn(logstr)
         time.sleep(0.005)
     except Exception, ex: handle_exception() ; result = str(ex)
     self.working = False
Ejemplo n.º 3
0
 def handle(self, speed, args):
     """ schedule a bot command. """
     try:
         descr, func, bot, ievent = args
         self.nowrunning = getname(func) + " - " + descr 
         self.starttime = time.time()
         if not ievent.nolog: logging.info("event handler is %s" % str(func))
         if self.nowrunning in self.longrunning and not self.nowrunning in self.shortrunning: 
             logging.warn("putting %s on longrunner" % self.nowrunning)
             longrunner.put(ievent.speed or speed, descr, func, bot, ievent)
             return
         self.working = True
         try: result = func(bot, ievent)
         except URLNotEnabled, ex: logging.warn("urls fetching is disabled (%s)" % ievent.usercmnd) ; return str(ex)
         self.finished = time.time()
         self.elapsed = self.finished - self.starttime
         if self.elapsed > 5:
             if self.nowrunning not in self.longrunning: self.longrunning.append(self.nowrunning)
             try: self.shortrunning.remove(self.nowrunning)
             except ValueError: pass
             if not ievent.nolog: logging.debug('ALERT %s %s job taking too long: %s seconds' % (descr, str(func), self.elapsed))
         stats.upitem(self.nowrunning)
         stats.upitem(self.name)
         time.sleep(0.005)
         logstr = "finished %s - %s - %s (%s)" % (self.nowrunning, result or "no result", ievent.cbtype, self.elapsed)
         if ievent.cbtype not in ['TICK', 'PING', 'NOTICE', 'TICK60']: logging.info(logstr)
     except Exception, ex:
         handle_exception()
         result = str(ex)
Ejemplo n.º 4
0
 def lockedfunc(*args, **kwargs):
     """ the locked function. """
     where = getname(str(func))
     try:
         rlockmanager.acquire(where)
         res = func(*args, **kwargs)
     finally: rlockmanager.release(where)
     return res
Ejemplo n.º 5
0
 def handle(self, descr, func, bot, ievent, *args, **kwargs):
     """ schedule a bot command. """
     try:
         self.starttime = time.time()
         lockmanager.acquire(getname(str(func)))
         name = getname(str(func))
         self.name = name
         self.working = True
         logging.debug("runner - now running %s" % name)
         func(bot, ievent, *args, **kwargs)
         self.finished = time.time()
         self.elapsed = self.finished - self.starttime
         if self.elapsed > 3:
             logging.info('runner - ALERT %s %s job taking too long: %s seconds' % (descr, str(func), self.elapsed))
         #if ievent.iscommand: ievent.ready()
         ievent.ready()
     except Exception, ex:
         handle_exception(ievent)
Ejemplo n.º 6
0
 def handle(self, descr, func, *args, **kwargs):
     """ schedule a job. """
     self.working = True
     name = getname(str(func))
     try:
         rlockmanager.acquire(getname(str(func)))
         name = getname(str(func))
         self.name = name
         logging.debug('runner - running %s: %s' % (descr, name))
         self.starttime = time.time()
         func(*args, **kwargs)
         self.finished = time.time()
         self.elapsed = self.finished - self.starttime
         if self.elapsed > 3:
             logging.debug('runner - ALERT %s %s job taking too long: %s seconds' % (descr, str(func), self.elapsed))
     except Exception, ex: handle_exception()
     finally: rlockmanager.release()
     self.working = False
Ejemplo n.º 7
0
 def lockedfunc(*args, **kwargs):
     """ the locked function. """
     where = getname(str(func))
     try:
         rlockmanager.acquire(where)
         res = func(*args, **kwargs)
     finally:
         rlockmanager.release(where)
     return res
Ejemplo n.º 8
0
Archivo: runner.py Proyecto: code2u/jsb
 def handle(self, descr, func, *args, **kwargs):
     """ schedule a job. """
     self.working = True
     name = getname(str(func))
     try:
         #rlockmanager.acquire(getname(str(func)))
         name = getname(str(func))
         self.name = name
         logging.debug('running %s: %s' % (descr, name))
         self.starttime = time.time()
         func(*args, **kwargs)
         self.finished = time.time()
         self.elapsed = self.finished - self.starttime
         if self.elapsed > 3:
             logging.debug('ALERT %s %s job taking too long: %s seconds' % (descr, str(func), self.elapsed))
     except Exception, ex: handle_exception()
     #finally: rlockmanager.release()
     self.working = False
Ejemplo n.º 9
0
Archivo: runner.py Proyecto: code2u/jsb
 def handle(self, descr, func, bot, ievent, *args, **kwargs):
     """ schedule a bot command. """
     try:
         self.starttime = time.time()
         lockmanager.acquire(getname(str(func)))
         name = getname(str(func))
         self.name = name
         self.working = True
         logging.debug("now running %s" % name)
         func(bot, ievent, *args, **kwargs)
         self.finished = time.time()
         self.elapsed = self.finished - self.starttime
         if self.elapsed > 3:
             logging.info('ALERT %s %s job taking too long: %s seconds' % (descr, str(func), self.elapsed))
         #if ievent.iscommand: ievent.ready()
         if not ievent.type == "OUTPUT" and not ievent.dontclose: ievent.ready()
         #time.sleep(0.001)
     except Exception, ex:
         handle_exception(ievent)
Ejemplo n.º 10
0
def handle_activity(bot, ievent):
    """ no arguments - show running threads. """
    try:
        import threading
    except ImportError:
        ievent.reply("threading is not enabled.")
        return
    result = {}
    todo = threadloops
    for thread in threadloops:
        name = "%s_%s" % (getname(type(thread)), thread.name)
        try:
            result[name] = date.duration(thread.lastiter, plain=True)
        except Exception, ex:
            logging.warn("%s - %s" % (name, str(ex)))
Ejemplo n.º 11
0
def handle_activity(bot, ievent):
    """ no arguments - show running threads. """
    try: import threading
    except ImportError:
         ievent.reply("threading is not enabled.")
         return
    result = {}
    todo = threadloops
    for thread in threadloops:
        name = "%s_%s" % (getname(type(thread)), thread.name)
        try: result[name] = date.duration(thread.lastiter, plain=True)
        except Exception, ex: logging.warn("%s - %s" % (name, str(ex))) 
    for b in getfleet().bots:
        try: result[b.cfg.name] = date.duration(b.lastiter, plain=True)
        except Exception, ex: logging.warn("%s - %s" % (name, str(ex))) 
        
    ievent.reply("last iterations: ", result)
Ejemplo n.º 12
0
 def handle(self, speed, args):
     """ schedule a bot command. """
     try:
         descr, func, bot, ievent = args
         self.nowrunning = getname(func) + " - " + descr 
         self.starttime = time.time()
         if not ievent.nolog: logging.debug("long event handler is %s" % str(func))
         self.working = True
         result = func(bot, ievent)
         self.elapsed = time.time() - self.starttime
         if self.elapsed < 1 and self.nowrunning not in self.shortrunning: self.shortrunning.append(self.nowrunning)
         stats.upitem(self.nowrunning)
         stats.upitem(self.name)
         logstr = "finished %s - %s - %s (%s)" % (self.nowrunning, result or "no result", ievent.cbtype, self.elapsed)
         if ievent.cbtype not in ['TICK', 'PING', 'NOTICE', 'TICK60']: logging.warn(logstr)
     except Exception, ex:
         handle_exception()
         result = str(ex)
Ejemplo n.º 13
0
 def handle(self, speed, args):
     """ schedule a bot command. """
     try:
         descr, func, bot, ievent = args
         self.nowrunning = getname(func) + " - " + descr
         self.starttime = time.time()
         if not ievent.nolog:
             logging.info("event handler is %s" % str(func))
         if self.nowrunning in self.longrunning and not self.nowrunning in self.shortrunning:
             logging.warn("putting %s on longrunner" % self.nowrunning)
             longrunner.put(ievent.speed or speed, descr, func, bot, ievent)
             return
         self.working = True
         try:
             result = func(bot, ievent)
         except URLNotEnabled, ex:
             logging.warn("urls fetching is disabled (%s)" %
                          ievent.usercmnd)
             return str(ex)
         self.finished = time.time()
         self.elapsed = self.finished - self.starttime
         if self.elapsed > 5:
             if self.nowrunning not in self.longrunning:
                 self.longrunning.append(self.nowrunning)
             try:
                 self.shortrunning.remove(self.nowrunning)
             except ValueError:
                 pass
             if not ievent.nolog:
                 logging.debug(
                     'ALERT %s %s job taking too long: %s seconds' %
                     (descr, str(func), self.elapsed))
         stats.upitem(self.nowrunning)
         stats.upitem(self.name)
         time.sleep(0.005)
         logstr = "finished %s - %s - %s (%s)" % (
             self.nowrunning, result
             or "no result", ievent.cbtype, self.elapsed)
         if ievent.cbtype not in ['TICK', 'PING', 'NOTICE', 'TICK60']:
             logging.info(logstr)
Ejemplo n.º 14
0
 def handle(self, speed, args):
     """ schedule a bot command. """
     try:
         descr, func, bot, ievent = args
         self.nowrunning = getname(func) + " - " + descr
         self.starttime = time.time()
         if not ievent.nolog:
             logging.debug("long event handler is %s" % str(func))
         self.working = True
         result = func(bot, ievent)
         self.elapsed = time.time() - self.starttime
         if self.elapsed < 1 and self.nowrunning not in self.shortrunning:
             self.shortrunning.append(self.nowrunning)
         stats.upitem(self.nowrunning)
         stats.upitem(self.name)
         logstr = "finished %s - %s - %s (%s)" % (
             self.nowrunning, result
             or "no result", ievent.cbtype, self.elapsed)
         if ievent.cbtype not in ['TICK', 'PING', 'NOTICE', 'TICK60']:
             logging.warn(logstr)
     except Exception, ex:
         handle_exception()
         result = str(ex)
Ejemplo n.º 15
0
 def names(self):
     return [getname(runner.name) for runner in self.runners]
Ejemplo n.º 16
0
 def names(self):
     return [getname(runner.name) for runner in self.runners]