diff options
-rw-r--r-- | bitbake/lib/bb/server/xmlrpc.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py index d0f5a6d6da..1a475e04ba 100644 --- a/bitbake/lib/bb/server/xmlrpc.py +++ b/bitbake/lib/bb/server/xmlrpc.py | |||
@@ -227,6 +227,8 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
227 | self.idle_timeout = idle_timeout | 227 | self.idle_timeout = idle_timeout |
228 | if idle_timeout: | 228 | if idle_timeout: |
229 | self.register_idle_function(self.handle_idle_timeout, self) | 229 | self.register_idle_function(self.handle_idle_timeout, self) |
230 | self.heartbeat_seconds = 1 # default, BB_HEARTBEAT_EVENT will be checked once we have a datastore. | ||
231 | self.next_heartbeat = time.time() | ||
230 | 232 | ||
231 | def addcooker(self, cooker): | 233 | def addcooker(self, cooker): |
232 | BaseImplServer.addcooker(self, cooker) | 234 | BaseImplServer.addcooker(self, cooker) |
@@ -250,6 +252,15 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
250 | return [] | 252 | return [] |
251 | 253 | ||
252 | def serve_forever(self): | 254 | def serve_forever(self): |
255 | heartbeat_event = self.cooker.data.getVar('BB_HEARTBEAT_EVENT') | ||
256 | if heartbeat_event: | ||
257 | try: | ||
258 | self.heartbeat_seconds = float(heartbeat_event) | ||
259 | except: | ||
260 | # Throwing an exception here causes bitbake to hang. | ||
261 | # Just warn about the invalid setting and continue | ||
262 | bb.warn('Ignoring invalid BB_HEARTBEAT_EVENT=%s, must be a float specifying seconds.' % heartbeat_event) | ||
263 | |||
253 | # Start the actual XMLRPC server | 264 | # Start the actual XMLRPC server |
254 | bb.cooker.server_main(self.cooker, self._serve_forever) | 265 | bb.cooker.server_main(self.cooker, self._serve_forever) |
255 | 266 | ||
@@ -297,6 +308,21 @@ class XMLRPCServer(SimpleXMLRPCServer, BaseImplServer): | |||
297 | # we ignore interrupted calls | 308 | # we ignore interrupted calls |
298 | pass | 309 | pass |
299 | 310 | ||
311 | # Create new heartbeat event? | ||
312 | now = time.time() | ||
313 | if now >= self.next_heartbeat: | ||
314 | # We might have missed heartbeats. Just trigger once in | ||
315 | # that case and continue after the usual delay. | ||
316 | self.next_heartbeat += self.heartbeat_seconds | ||
317 | if self.next_heartbeat <= now: | ||
318 | self.next_heartbeat = now + self.heartbeat_seconds | ||
319 | heartbeat = bb.event.HeartbeatEvent(now) | ||
320 | bb.event.fire(heartbeat, self.cooker.data) | ||
321 | if nextsleep and now + nextsleep > self.next_heartbeat: | ||
322 | # Shorten timeout so that we we wake up in time for | ||
323 | # the heartbeat. | ||
324 | nextsleep = self.next_heartbeat - now | ||
325 | |||
300 | # Tell idle functions we're exiting | 326 | # Tell idle functions we're exiting |
301 | for function, data in list(self._idlefuns.items()): | 327 | for function, data in list(self._idlefuns.items()): |
302 | try: | 328 | try: |