fix lock acquisition when scheduling builds

lock should be acquired when fetching versions, not checking for
existing build; intent is to prevent selecting a version in the middle
of a sequence of versions being concurrently saved by another ATC