def get(self): # look up instances that were updated more than 15 minutes ago instances = Instance.get_older_than(900) # loop through results and mark returned instances as 'inactive' if instances: for instance in instances: if instance.state == 1 and instance.reserved == False: logging.info("Marking instance=(%s) stale." % instance.name) instance.state = 0 instance.put() # notification channel if instance.token: channel_message(instance.token, "stale") # look up instances that were updated more than 24 hours ago instances = Instance.get_older_than(86400) # loop through results and delete them if instances: for instance in instances: # whack instances that are decomissioned or never been started if instance.state == 7 or instance.state < 3: logging.info("Deleting stale instance=(%s)." % instance.name) instance.key.delete() # notification channel if instance.token: channel_message(instance.token, "delete") return