File tree 3 files changed +51
-2
lines changed
3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 19
19
)
20
20
from readthedocs .doc_builder .constants import DOCKER_LIMITS
21
21
from readthedocs .projects .constants import CELERY_LOW , CELERY_MEDIUM , CELERY_HIGH
22
- from readthedocs .doc_builder .exceptions import BuildMaxConcurrencyError
22
+ from readthedocs .doc_builder .exceptions import BuildMaxConcurrencyError , DuplicatedBuildError
23
23
24
24
25
25
log = logging .getLogger (__name__ )
@@ -165,8 +165,42 @@ def prepare_build(
165
165
# External builds should be lower priority.
166
166
options ['priority' ] = CELERY_LOW
167
167
168
+ skip_build = False
169
+ if commit :
170
+ skip_build = (
171
+ Build .objects
172
+ .filter (
173
+ project = project ,
174
+ version = version ,
175
+ commit = commit ,
176
+ ).exclude (
177
+ state = BUILD_STATE_FINISHED ,
178
+ ).exists ()
179
+ )
180
+ else :
181
+ skip_build = Build .objects .filter (
182
+ project = project ,
183
+ version = version ,
184
+ state = BUILD_STATE_TRIGGERED ,
185
+ ).count () > 0
186
+ if skip_build :
187
+ # TODO: we could mark the old build as duplicated, however we reset our
188
+ # position in the queue and go back to the end of it --penalization
189
+ log .warning (
190
+ 'Marking build to be skipped by builder. project=%s version=%s build=%s commit=%s' ,
191
+ project .slug ,
192
+ version .slug ,
193
+ build .pk ,
194
+ commit ,
195
+ )
196
+ build .error = DuplicatedBuildError .message
197
+ build .success = False
198
+ build .exit_code = 1
199
+ build .state = BUILD_STATE_FINISHED
200
+ build .save ()
201
+
168
202
# Start the build in X minutes and mark it as limited
169
- if project .has_feature (Feature .LIMIT_CONCURRENT_BUILDS ):
203
+ if not skip_build and project .has_feature (Feature .LIMIT_CONCURRENT_BUILDS ):
170
204
running_builds = (
171
205
Build .objects
172
206
.filter (project__slug = project .slug )
Original file line number Diff line number Diff line change @@ -57,6 +57,10 @@ class BuildMaxConcurrencyError(BuildEnvironmentError):
57
57
message = ugettext_noop ('Concurrency limit reached ({limit}), retrying in 5 minutes.' )
58
58
59
59
60
+ class DuplicatedBuildError (BuildEnvironmentError ):
61
+ message = ugettext_noop ('Duplicated build.' )
62
+
63
+
60
64
class BuildEnvironmentWarning (BuildEnvironmentException ):
61
65
pass
62
66
Original file line number Diff line number Diff line change 58
58
BuildEnvironmentWarning ,
59
59
BuildMaxConcurrencyError ,
60
60
BuildTimeoutError ,
61
+ DuplicatedBuildError ,
61
62
MkDocsYAMLParseError ,
62
63
ProjectBuildsSkippedError ,
63
64
VersionLockedError ,
@@ -542,6 +543,16 @@ def run(
542
543
self .commit = commit
543
544
self .config = None
544
545
546
+ if self .build ['state' ] == BUILD_STATE_FINISHED and self .build ['error' ] == DuplicatedBuildError .message :
547
+ log .warning (
548
+ 'NOOP: build is marked as duplicated. project=%s version=%s build=%s commit=%s' ,
549
+ self .project .slug ,
550
+ self .version .slug ,
551
+ build_pk ,
552
+ self .commit ,
553
+ )
554
+ return True
555
+
545
556
if self .project .has_feature (Feature .LIMIT_CONCURRENT_BUILDS ):
546
557
response = api_v2 .build .running .get (project__slug = self .project .slug )
547
558
builds_running = response .get ('count' , 0 )
You can’t perform that action at this time.
0 commit comments