Package ZenHub :: Package services :: Module Procrastinator
[hide private]
[frames] | no frames]

Source Code for Module ZenHub.services.Procrastinator

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13  from sets import Set 
14   
15 -class Procrastinate:
16 "A class to delay executing a change to a device" 17
18 - def __init__(self, cback):
19 self.cback = cback 20 self.devices = Set() 21 self.timer = None
22
23 - def clear(self):
24 self.devices = Set()
25
26 - def doLater(self, device = None):
27 if self.timer and not self.timer.called: 28 self.timer.cancel() 29 self.devices.add(device) 30 from twisted.internet import reactor 31 self.timer = reactor.callLater(5, self._doNow)
32 33
34 - def _doNow(self, *unused):
35 if self.devices: 36 device = self.devices.pop() 37 d = self.cback(device) 38 if d: 39 d.addBoth(self._doNow)
40