Skip to content

Commit cd329d6

Browse files
committed
Call lock per task
This lock was being shared by sync_repo and build_docs, I'm moving it to the top of the tasks instead.
1 parent bbee0c7 commit cd329d6

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

readthedocs/projects/tasks.py

+25-32
Original file line numberDiff line numberDiff line change
@@ -133,28 +133,27 @@ def sync_repo(self):
133133
),
134134
)
135135

136-
with self.project.repo_nonblockinglock(version=self.version):
137-
# Get the actual code on disk
138-
try:
139-
before_vcs.send(sender=self.version)
140-
msg = 'Checking out version {slug}: {identifier}'.format(
141-
slug=self.version.slug,
142-
identifier=self.version.identifier,
143-
)
144-
log.info(
145-
LOG_TEMPLATE,
146-
{
147-
'project': self.project.slug,
148-
'version': self.version.slug,
149-
'msg': msg,
150-
}
151-
)
152-
version_repo = self.get_vcs_repo()
153-
version_repo.update()
154-
self.sync_versions(version_repo)
155-
version_repo.checkout(self.version.identifier)
156-
finally:
157-
after_vcs.send(sender=self.version)
136+
# Get the actual code on disk
137+
try:
138+
before_vcs.send(sender=self.version)
139+
msg = 'Checking out version {slug}: {identifier}'.format(
140+
slug=self.version.slug,
141+
identifier=self.version.identifier,
142+
)
143+
log.info(
144+
LOG_TEMPLATE,
145+
{
146+
'project': self.project.slug,
147+
'version': self.version.slug,
148+
'msg': msg,
149+
}
150+
)
151+
version_repo = self.get_vcs_repo()
152+
version_repo.update()
153+
self.sync_versions(version_repo)
154+
version_repo.checkout(self.version.identifier)
155+
finally:
156+
after_vcs.send(sender=self.version)
158157

159158
def sync_versions(self, version_repo):
160159
"""
@@ -242,7 +241,8 @@ def run(self, version_pk): # pylint: disable=arguments-differ
242241
try:
243242
self.version = self.get_version(version_pk=version_pk)
244243
self.project = self.version.project
245-
self.sync_repo()
244+
with self.project.repo_nonblockinglock(version=self.version):
245+
self.sync_repo()
246246
return True
247247
except RepositoryError:
248248
# Do not log as ERROR handled exceptions
@@ -442,7 +442,8 @@ def run_setup(self, record=True):
442442
if self.project.skip:
443443
raise ProjectBuildsSkippedError
444444
try:
445-
self.setup_vcs()
445+
with self.project.repo_nonblockinglock(version=self.version):
446+
self.setup_vcs()
446447
except vcs_support_utils.LockTimeout as e:
447448
self.task.retry(exc=e, throw=False)
448449
raise VersionLockedError
@@ -628,14 +629,6 @@ def setup_vcs(self):
628629
log.warning('There was an error with the repository', exc_info=True)
629630
# Re raise the exception to stop the build at this point
630631
raise
631-
except vcs_support_utils.LockTimeout:
632-
log.info(
633-
'Lock still active: project=%s version=%s',
634-
self.project.slug,
635-
self.version.slug,
636-
)
637-
# Raise the proper exception (won't be sent to Sentry)
638-
raise VersionLockedError
639632
except Exception:
640633
# Catch unhandled errors when syncing
641634
log.exception(

0 commit comments

Comments
 (0)