def get_bot_version(host): """Retrieves the bot version (SHA-1) loaded on this server. The memcache is first checked for the version, otherwise the value is generated and then stored in the memcache. Returns: The hash of the current bot version. """ # This is invalidate everything bot_config is uploaded. bot_versions = memcache.get('versions', namespace='bot_code') or {} # CURRENT_VERSION_ID is unique per upload so it can be trusted. app_ver = host + '-' + os.environ['CURRENT_VERSION_ID'] bot_version = bot_versions.get(app_ver) if bot_version: return bot_version # Need to calculate it. additionals = {'config/bot_config.py': get_bot_config().content} bot_dir = os.path.join(ROOT_DIR, 'swarming_bot') bot_version = bot_archive.get_swarming_bot_version( bot_dir, host, utils.get_app_version(), additionals) if len(bot_versions) > 100: # Lazy discard when too large. bot_versions = {} bot_versions[app_ver] = bot_version memcache.set('versions', bot_versions, namespace='bot_code') return bot_version
def get_bot_version(host): """Retrieves the current bot version (SHA256) loaded on this server. The memcache is first checked for the version, otherwise the value is generated and then stored in the memcache. Returns: tuple(hash of the current bot version, dict of additional files). """ signature = _get_signature(host) version = memcache.get('version-' + signature, namespace='bot_code') if version: return version, None # Need to calculate it. additionals = {'config/bot_config.py': get_bot_config().content} bot_dir = os.path.join(ROOT_DIR, 'swarming_bot') version = bot_archive.get_swarming_bot_version(bot_dir, host, utils.get_app_version(), additionals, local_config.settings()) memcache.set('version-' + signature, version, namespace='bot_code', time=60) return version, additionals
def get_bot_version(host): """Retrieves the bot version loaded on this server. The memcache is first checked for the version, otherwise the value is generated and then stored in the memcache. Returns: The hash of the current bot version. """ namespace = os.environ['CURRENT_VERSION_ID'] key = 'bot_version' + host bot_version = memcache.get(key, namespace=namespace) if bot_version: return bot_version # Need to calculate it. additionals = {'bot_config.py': get_bot_config().content} bot_dir = os.path.join(ROOT_DIR, 'swarming_bot') bot_version = bot_archive.get_swarming_bot_version(bot_dir, host, additionals) memcache.set(key, bot_version, namespace=namespace) return bot_version