def _on_heartbeat(self, ch, method, properties, message):
message = json.loads(str(message))
pid = message.get("uuid")
try:
p = model.Plugin.objects.get(uuid=pid)
# update heartbeat timestamp
p.last_heartbeat_at = datetime.datetime.now()
change = False
# TODO ugly: state management of plugins should be hidden with plugin class
if message.get("state") == "READY" and p.state != "READY":
# a plugin just announced that it is ready, lets start it
self.send_start_notification(p)
change = True
elif message.get("state") != p.state:
# lets keep track of the reported state update
p.state = message.get("state")
change = True
p.save()
if change:
# there was a state change lets schedule an plugin status update notification
self.send_plugin_status_update()
except DoesNotExist:
LOG.debug("Couldn't find plugin with UUID %r in DB" % pid)
评论列表
文章目录