def _GetSafeServerInstance(self): '''Returns a ServerInstance with a host file system at a safe revision, meaning the last revision that the current running version of the server existed. ''' delegate = self._delegate # IMPORTANT: Get a ServerInstance pinned to the most recent revision, not # HEAD. These cron jobs take a while and run very frequently such that # there is usually one running at any given time, and eventually a file # that we're dealing with will change underneath it, putting the server in # an undefined state. server_instance_near_head = self._CreateServerInstance( self._GetMostRecentRevision()) app_yaml_handler = AppYamlHelper( server_instance_near_head.object_store_creator, server_instance_near_head.host_file_system_provider) if app_yaml_handler.IsUpToDate(delegate.GetAppVersion()): return server_instance_near_head # The version in app.yaml is greater than the currently running app's. # The safe version is the one before it changed. safe_revision = app_yaml_handler.GetFirstRevisionGreaterThan( delegate.GetAppVersion()) - 1 _cronlog.info('app version %s is out of date, safe is %s', delegate.GetAppVersion(), safe_revision) return self._CreateServerInstance(safe_revision)
def _GetSafeServerInstance(self): '''Returns a ServerInstance with a host file system at a safe revision, meaning the last revision that the current running version of the server existed. ''' delegate = self._delegate server_instance_at_head = self._CreateServerInstance(None) app_yaml_handler = AppYamlHelper( svn_constants.APP_YAML_PATH, server_instance_at_head.host_file_system, server_instance_at_head.object_store_creator, server_instance_at_head.host_file_system_creator) if app_yaml_handler.IsUpToDate(delegate.GetAppVersion()): # TODO(kalman): return a new ServerInstance at an explicit revision in # case the HEAD version changes underneath us. return server_instance_at_head # The version in app.yaml is greater than the currently running app's. # The safe version is the one before it changed. safe_revision = app_yaml_handler.GetFirstRevisionGreaterThan( delegate.GetAppVersion()) - 1 logging.info('cron: app version %s is out of date, safe is %s' % (delegate.GetAppVersion(), safe_revision)) return self._CreateServerInstance(safe_revision)
def _GetSafeServerInstance(self): '''Returns a ServerInstance with a host file system at a safe revision, meaning the last revision that the current running version of the server existed. ''' channel = self._channel delegate = self._delegate server_instance_at_head = self._CreateServerInstance(channel, None) get_branch_for_channel = self._GetBranchForChannel class AppYamlHelperDelegate(AppYamlHelper.Delegate): def GetHostFileSystemForRevision(self, revision): return delegate.CreateHostFileSystemForBranchAndRevision( get_branch_for_channel(channel), revision) app_yaml_handler = AppYamlHelper( svn_constants.APP_YAML_PATH, server_instance_at_head.host_file_system, AppYamlHelperDelegate(), server_instance_at_head.object_store_creator) if app_yaml_handler.IsUpToDate(delegate.GetAppVersion()): # TODO(kalman): return a new ServerInstance at an explicit revision in # case the HEAD version changes underneath us. return server_instance_at_head # The version in app.yaml is greater than the currently running app's. # The safe version is the one before it changed. safe_revision = app_yaml_handler.GetFirstRevisionGreaterThan( delegate.GetAppVersion()) - 1 logging.info('cron/%s: app version %s is out of date, safe is %s' % ( channel, delegate.GetAppVersion(), safe_revision)) return self._CreateServerInstance(channel, safe_revision)