annotate bitten/queue.py @ 883:dfbf2f857a50

Fixed handling of active configurations that points to deleted branches. Configurations and builds can now be checked and displayed even though the repository path cannot be found for last revision. It uses configuration 'last' (`max_rev`) to "close" the configuration. Closes #606. Thanks to falkb for extensive testing.
author osimons
date Fri, 10 Dec 2010 09:23:12 +0000
parents 7c80375d4817
children ed77e3e1c43f
rev   line source
379
0df178e07fdb Use UTF-8 as encoding of source files.
cmlenz
parents: 377
diff changeset
1 # -*- coding: utf-8 -*-
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
2 #
832
7c80375d4817 Updated copyright to 2010.
osimons
parents: 804
diff changeset
3 # Copyright (C) 2007-2010 Edgewall Software
408
933105ab516b Update file headers and other stuff pointing to the old home.
cmlenz
parents: 400
diff changeset
4 # Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
5 # All rights reserved.
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
6 #
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
7 # This software is licensed as described in the file COPYING, which
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
8 # you should have received as part of this distribution. The terms
408
933105ab516b Update file headers and other stuff pointing to the old home.
cmlenz
parents: 400
diff changeset
9 # are also available at http://bitten.edgewall.org/wiki/License.
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
10
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
11 """Implements the scheduling of builds for a project.
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
12
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
13 This module provides the functionality for scheduling builds for a specific
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
14 Trac environment. It is used by both the build master and the web interface to
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
15 get the list of required builds (revisions not built yet).
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
16
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
17 Furthermore, the `BuildQueue` class is used by the build master to determine
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
18 the next pending build, and to match build slaves against configured target
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
19 platforms.
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
20 """
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
21
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
22 from itertools import ifilter
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
23 import re
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
24 import time
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
25
585
87de4513bfdd 0.6dev: Cleaning remaining 'frontend' datetime code - at least down to all code that interface with the various `model` classes that still only works with timestamps for input and output. See #85.
osimons
parents: 581
diff changeset
26 from trac.util.datefmt import to_timestamp
762
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 745
diff changeset
27 from trac.util import pretty_timedelta, format_datetime
745
91aabd647610 Delete attachments when builds are cancelled/invalidated.
wbell
parents: 650
diff changeset
28 from trac.attachment import Attachment
91aabd647610 Delete attachments when builds are cancelled/invalidated.
wbell
parents: 650
diff changeset
29
585
87de4513bfdd 0.6dev: Cleaning remaining 'frontend' datetime code - at least down to all code that interface with the various `model` classes that still only works with timestamps for input and output. See #85.
osimons
parents: 581
diff changeset
30
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
31 from bitten.model import BuildConfig, TargetPlatform, Build, BuildStep
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
32
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
33 __docformat__ = 'restructuredtext en'
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
34
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
35
258
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 253
diff changeset
36 def collect_changes(repos, config, db=None):
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
37 """Collect all changes for a build configuration that either have already
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
38 been built, or still need to be built.
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
39
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
40 This function is a generator that yields ``(platform, rev, build)`` tuples,
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
41 where ``platform`` is a `TargetPlatform` object, ``rev`` is the identifier
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
42 of the changeset, and ``build`` is a `Build` object or `None`.
313
90422699a594 More and improved docstrings (using epydoc format).
cmlenz
parents: 295
diff changeset
43
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
44 :param repos: the version control repository
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
45 :param config: the build configuration
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
46 :param db: a database connection (optional)
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
47 """
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
48 env = config.env
258
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 253
diff changeset
49 if not db:
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 253
diff changeset
50 db = env.get_db_cnx()
395
37e30696c0a8 Don't raise an exception when the repository node associated with a build config has been since removed.
cmlenz
parents: 392
diff changeset
51 try:
883
dfbf2f857a50 Fixed handling of active configurations that points to deleted branches.
osimons
parents: 832
diff changeset
52 node = repos.get_node(config.path, config.max_rev)
581
2cc06425117a 0.6dev: Handle any error accessing a repository node. Closes #416.
osimons
parents: 513
diff changeset
53 except Exception, e:
2cc06425117a 0.6dev: Handle any error accessing a repository node. Closes #416.
osimons
parents: 513
diff changeset
54 env.log.warn('Error accessing path %r for configuration %r',
2cc06425117a 0.6dev: Handle any error accessing a repository node. Closes #416.
osimons
parents: 513
diff changeset
55 config.path, config.name, exc_info=True)
395
37e30696c0a8 Don't raise an exception when the repository node associated with a build config has been since removed.
cmlenz
parents: 392
diff changeset
56 return
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
57
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
58 for path, rev, chg in node.get_history():
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
59
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
60 # Don't follow moves/copies
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
61 if path != repos.normalize_path(config.path):
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
62 break
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
63
231
4a9cf87d443f Allow the build queue for a configuration to be limited to a range between `min_rev` and `max_rev`.
cmlenz
parents: 228
diff changeset
64 # Stay within the limits of the build config
4a9cf87d443f Allow the build queue for a configuration to be limited to a range between `min_rev` and `max_rev`.
cmlenz
parents: 228
diff changeset
65 if config.min_rev and repos.rev_older_than(rev, config.min_rev):
4a9cf87d443f Allow the build queue for a configuration to be limited to a range between `min_rev` and `max_rev`.
cmlenz
parents: 228
diff changeset
66 break
4a9cf87d443f Allow the build queue for a configuration to be limited to a range between `min_rev` and `max_rev`.
cmlenz
parents: 228
diff changeset
67 if config.max_rev and repos.rev_older_than(config.max_rev, rev):
4a9cf87d443f Allow the build queue for a configuration to be limited to a range between `min_rev` and `max_rev`.
cmlenz
parents: 228
diff changeset
68 continue
4a9cf87d443f Allow the build queue for a configuration to be limited to a range between `min_rev` and `max_rev`.
cmlenz
parents: 228
diff changeset
69
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
70 # Make sure the repository directory isn't empty at this
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
71 # revision
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
72 old_node = repos.get_node(path, rev)
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
73 is_empty = True
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
74 for entry in old_node.get_entries():
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
75 is_empty = False
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
76 break
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
77 if is_empty:
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
78 continue
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
79
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
80 # For every target platform, check whether there's a build
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
81 # of this revision
258
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 253
diff changeset
82 for platform in TargetPlatform.select(env, config.name, db=db):
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 253
diff changeset
83 builds = list(Build.select(env, config.name, rev, platform.id,
77cdef044d48 * Improve build log formatter performance: now only matches strings using the `path:line` format, and checks the existance of files in the repository when they are encountered. Should fix (or at least improve) #54.
cmlenz
parents: 253
diff changeset
84 db=db))
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
85 if builds:
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
86 build = builds[0]
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
87 else:
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
88 build = None
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
89
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
90 yield platform, rev, build
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
91
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
92
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
93 class BuildQueue(object):
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
94 """Enapsulates the build queue of an environment.
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
95
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
96 A build queue manages the the registration of build slaves and detection of
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
97 repository revisions that need to be built.
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
98 """
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
99
468
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
100 def __init__(self, env, build_all=False, stabilize_wait=0, timeout=0):
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
101 """Create the build queue.
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
102
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
103 :param env: the Trac environment
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
104 :param build_all: whether older revisions should be built
468
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
105 :param stabilize_wait: The time in seconds to wait before considering
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
106 the repository stable to create a build in the queue.
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
107 :param timeout: the time in seconds after which an in-progress build
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
108 should be considered orphaned, and reset to pending
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
109 state
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
110 """
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
111 self.env = env
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
112 self.log = env.log
348
ef795ebeac00 Updated change log for [milestone:0.5.3].
cmlenz
parents: 318
diff changeset
113 self.build_all = build_all
468
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
114 self.stabilize_wait = stabilize_wait
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
115 self.timeout = timeout
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
116
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
117 # Build scheduling
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
118
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
119 def get_build_for_slave(self, name, properties):
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
120 """Check whether one of the pending builds can be built by the build
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
121 slave.
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
122
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
123 :param name: the name of the slave
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
124 :type name: `basestring`
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
125 :param properties: the slave configuration
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
126 :type properties: `dict`
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
127 :return: the allocated build, or `None` if no build was found
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
128 :rtype: `Build`
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
129 """
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
130 self.log.debug('Checking for pending builds...')
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
131
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
132 db = self.env.get_db_cnx()
348
ef795ebeac00 Updated change log for [milestone:0.5.3].
cmlenz
parents: 318
diff changeset
133 repos = self.env.get_repository()
804
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
134 assert repos, 'No "(default)" Repository: Add a repository or alias ' \
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
135 'named "(default)" to Trac.'
372
67372eba421c Change building order; rather than just build in reverse revision order (which tends to get stuck if you have a bunch of revisions on a single branch), build the newest revision on each branch before you go backwards and fill in the previous revisions.
wbell
parents: 363
diff changeset
136
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
137 self.reset_orphaned_builds()
372
67372eba421c Change building order; rather than just build in reverse revision order (which tends to get stuck if you have a bunch of revisions on a single branch), build the newest revision on each branch before you go backwards and fill in the previous revisions.
wbell
parents: 363
diff changeset
138
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
139 # Iterate through pending builds by descending revision timestamp, to
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
140 # avoid the first configuration/platform getting all the builds
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
141 platforms = [p.id for p in self.match_slave(name, properties)]
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
142 builds_to_delete = []
639
5e78705333c3 0.6dev: Fixing a possible situation of two slaves claiming the same build. Closes #95.
osimons
parents: 606
diff changeset
143 build_found = False
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
144 for build in Build.select(self.env, status=Build.PENDING, db=db):
377
a465b5dbfecf Tabs and line length.
cmlenz
parents: 372
diff changeset
145 if self.should_delete_build(build, repos):
447
cdce97e97cca Fix bug in log statement introduced in [493].
cmlenz
parents: 446
diff changeset
146 self.log.info('Scheduling build %d for deletion', build.id)
446
a8c331c2d500 Attempt at a fix for #165.
cmlenz
parents: 444
diff changeset
147 builds_to_delete.append(build)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
148 elif build.platform in platforms:
639
5e78705333c3 0.6dev: Fixing a possible situation of two slaves claiming the same build. Closes #95.
osimons
parents: 606
diff changeset
149 build_found = True
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
150 break
639
5e78705333c3 0.6dev: Fixing a possible situation of two slaves claiming the same build. Closes #95.
osimons
parents: 606
diff changeset
151 if not build_found:
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
152 self.log.debug('No pending builds.')
448
ccddf91740d1 Fix deletion of obsolete builds in build queue.
cmlenz
parents: 447
diff changeset
153 build = None
372
67372eba421c Change building order; rather than just build in reverse revision order (which tends to get stuck if you have a bunch of revisions on a single branch), build the newest revision on each branch before you go backwards and fill in the previous revisions.
wbell
parents: 363
diff changeset
154
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
155 # delete any obsolete builds
448
ccddf91740d1 Fix deletion of obsolete builds in build queue.
cmlenz
parents: 447
diff changeset
156 for build_to_delete in builds_to_delete:
ccddf91740d1 Fix deletion of obsolete builds in build queue.
cmlenz
parents: 447
diff changeset
157 build_to_delete.delete(db=db)
372
67372eba421c Change building order; rather than just build in reverse revision order (which tends to get stuck if you have a bunch of revisions on a single branch), build the newest revision on each branch before you go backwards and fill in the previous revisions.
wbell
parents: 363
diff changeset
158
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
159 if build:
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
160 build.slave = name
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
161 build.slave_info.update(properties)
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
162 build.status = Build.IN_PROGRESS
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
163 build.update(db=db)
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
164
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
165 if build or builds_to_delete:
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
166 db.commit()
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
167
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
168 return build
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
169
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
170 def match_slave(self, name, properties):
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
171 """Match a build slave against available target platforms.
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
172
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
173 :param name: the name of the slave
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
174 :type name: `basestring`
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
175 :param properties: the slave configuration
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
176 :type properties: `dict`
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
177 :return: the list of platforms the slave matched
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
178 """
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
179 platforms = []
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
180
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
181 for config in BuildConfig.select(self.env):
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
182 for platform in TargetPlatform.select(self.env, config=config.name):
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
183 match = True
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
184 for propname, pattern in ifilter(None, platform.rules):
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
185 try:
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
186 propvalue = properties.get(propname)
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
187 if not propvalue or not re.match(pattern, propvalue):
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
188 match = False
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
189 break
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
190 except re.error:
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
191 self.log.error('Invalid platform matching pattern "%s"',
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
192 pattern, exc_info=True)
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
193 match = False
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
194 break
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
195 if match:
443
1c922d944bd2 Minor improvement to logging in the build master when matching slaves against target platforms.
cmlenz
parents: 437
diff changeset
196 self.log.debug('Slave %r matched target platform %r of '
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
197 'build configuration %r', name,
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
198 platform.name, config.name)
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
199 platforms.append(platform)
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
200
443
1c922d944bd2 Minor improvement to logging in the build master when matching slaves against target platforms.
cmlenz
parents: 437
diff changeset
201 if not platforms:
444
22d6a7da8777 Another minor improvement to logging in the build master.
cmlenz
parents: 443
diff changeset
202 self.log.warning('Slave %r matched none of the target platforms',
22d6a7da8777 Another minor improvement to logging in the build master.
cmlenz
parents: 443
diff changeset
203 name)
443
1c922d944bd2 Minor improvement to logging in the build master when matching slaves against target platforms.
cmlenz
parents: 437
diff changeset
204
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
205 return platforms
372
67372eba421c Change building order; rather than just build in reverse revision order (which tends to get stuck if you have a bunch of revisions on a single branch), build the newest revision on each branch before you go backwards and fill in the previous revisions.
wbell
parents: 363
diff changeset
206
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
207 def populate(self):
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
208 """Add a build for the next change on each build configuration to the
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
209 queue.
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
210
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
211 The next change is the latest repository check-in for which there isn't
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
212 a corresponding build on each target platform. Repeatedly calling this
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
213 method will eventually result in the entire change history of the build
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
214 configuration being in the build queue.
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
215 """
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
216 repos = self.env.get_repository()
804
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
217 assert repos, 'No "(default)" Repository: Add a repository or alias ' \
4c73a3cea9f5 Basic Trac 0.12 support, supporting just a `(default)` repository - essentially Trac 0.11 behaviour. Thanks to those that have contributed to #480 to get this working and tested.
osimons
parents: 762
diff changeset
218 'named "(default)" to Trac.'
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
219
360
5bc81e597352 Fix incompatibility with a change to the versioncontrol layer in Trac 0.10.3
cmlenz
parents: 352
diff changeset
220 db = self.env.get_db_cnx()
5bc81e597352 Fix incompatibility with a change to the versioncontrol layer in Trac 0.10.3
cmlenz
parents: 352
diff changeset
221 builds = []
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
222
360
5bc81e597352 Fix incompatibility with a change to the versioncontrol layer in Trac 0.10.3
cmlenz
parents: 352
diff changeset
223 for config in BuildConfig.select(self.env, db=db):
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
224 platforms = []
360
5bc81e597352 Fix incompatibility with a change to the versioncontrol layer in Trac 0.10.3
cmlenz
parents: 352
diff changeset
225 for platform, rev, build in collect_changes(repos, config, db):
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
226
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
227 if not self.build_all and platform.id in platforms:
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
228 # We've seen this platform already, so these are older
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
229 # builds that should only be built if built_all=True
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
230 self.log.debug('Ignoring older revisions for configuration '
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
231 '%r on %r', config.name, platform.name)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
232 break
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
233
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
234 platforms.append(platform.id)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 448
diff changeset
235
360
5bc81e597352 Fix incompatibility with a change to the versioncontrol layer in Trac 0.10.3
cmlenz
parents: 352
diff changeset
236 if build is None:
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
237 self.log.info('Enqueuing build of configuration "%s" at '
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
238 'revision [%s] on %s', config.name, rev,
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
239 platform.name)
437
6d5ac24061dc Fix build queue population compatiblity with Trac 0.11, where revision timestamps are `datetime` objects.
cmlenz
parents: 419
diff changeset
240
585
87de4513bfdd 0.6dev: Cleaning remaining 'frontend' datetime code - at least down to all code that interface with the various `model` classes that still only works with timestamps for input and output. See #85.
osimons
parents: 581
diff changeset
241 rev_time = to_timestamp(repos.get_changeset(rev).date)
468
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
242 age = int(time.time()) - rev_time
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
243 if self.stabilize_wait and age < self.stabilize_wait:
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
244 self.log.info('Delaying build of revision %s until %s '
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
245 'seconds pass. Current age is: %s '
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
246 'seconds' % (rev, self.stabilize_wait,
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
247 age))
44c2b4ac6157 Add stabilization time parameter to build master. Closes #189. Many thanks to Allen Bierbaum for the patch.
cmlenz
parents: 450
diff changeset
248 continue
437
6d5ac24061dc Fix build queue population compatiblity with Trac 0.11, where revision timestamps are `datetime` objects.
cmlenz
parents: 419
diff changeset
249
360
5bc81e597352 Fix incompatibility with a change to the versioncontrol layer in Trac 0.10.3
cmlenz
parents: 352
diff changeset
250 build = Build(self.env, config=config.name,
5bc81e597352 Fix incompatibility with a change to the versioncontrol layer in Trac 0.10.3
cmlenz
parents: 352
diff changeset
251 platform=platform.id, rev=str(rev),
437
6d5ac24061dc Fix build queue population compatiblity with Trac 0.11, where revision timestamps are `datetime` objects.
cmlenz
parents: 419
diff changeset
252 rev_time=rev_time)
360
5bc81e597352 Fix incompatibility with a change to the versioncontrol layer in Trac 0.10.3
cmlenz
parents: 352
diff changeset
253 builds.append(build)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
254
360
5bc81e597352 Fix incompatibility with a change to the versioncontrol layer in Trac 0.10.3
cmlenz
parents: 352
diff changeset
255 for build in builds:
650
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
256 try:
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
257 build.insert(db=db)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
258 db.commit()
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
259 except Exception, e:
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
260 # really only want to catch IntegrityErrors raised when
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
261 # a second slave attempts to add builds with the same
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
262 # (config, platform, rev) as an existing build.
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
263 self.log.info('Failed to insert build of configuration "%s" '
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
264 'at revision [%s] on platform [%s]: %s',
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
265 build.config, build.rev, build.platform, e)
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 643
diff changeset
266 db.rollback()
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
267
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
268 def reset_orphaned_builds(self):
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
269 """Reset all in-progress builds to ``PENDING`` state if they've been
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
270 running so long that the configured timeout has been reached.
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
271
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
272 This is used to cleanup after slaves that have unexpectedly cancelled
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
273 a build without notifying the master, or are for some other reason not
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
274 reporting back status updates.
228
a8c9dd7e3f71 * Cleanup and documentation for the `BuildQueue` class added in [236].
cmlenz
parents: 227
diff changeset
275 """
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
276 if not self.timeout:
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
277 # If no timeout is set, none of the in-progress builds can be
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
278 # considered orphaned
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
279 return
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
280
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
281 db = self.env.get_db_cnx()
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
282 now = int(time.time())
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
283 for build in Build.select(self.env, status=Build.IN_PROGRESS, db=db):
762
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 745
diff changeset
284 if now - build.last_activity < self.timeout:
419
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
285 # This build has not reached the timeout yet, assume it's still
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
286 # being executed
b72802dc0632 Fix resetting of builds when multiple slaves are building simultaneously, and implement the `slave_timeout` trac.ini option.
cmlenz
parents: 411
diff changeset
287 continue
762
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 745
diff changeset
288
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 745
diff changeset
289 self.log.info('Orphaning build %d. Last activity was %s (%s)' % \
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 745
diff changeset
290 (build.id, format_datetime(build.last_activity),
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 745
diff changeset
291 pretty_timedelta(build.last_activity)))
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 745
diff changeset
292
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
293 build.status = Build.PENDING
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
294 build.slave = None
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
295 build.slave_info = {}
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
296 build.started = 0
762
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 745
diff changeset
297 build.stopped = 0
5f0cfee44540 Add new last_activity field to build. I considered reusing stopped, but this seemed cleaner and more obvious, which seems like the right way to go.
wbell
parents: 745
diff changeset
298 build.last_activity = 0
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
299 for step in list(BuildStep.select(self.env, build=build.id, db=db)):
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
300 step.delete(db=db)
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
301 build.update(db=db)
745
91aabd647610 Delete attachments when builds are cancelled/invalidated.
wbell
parents: 650
diff changeset
302
91aabd647610 Delete attachments when builds are cancelled/invalidated.
wbell
parents: 650
diff changeset
303 Attachment.delete_all(self.env, 'build', build.resource.id, db)
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
304 db.commit()
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
305
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
306 def should_delete_build(self, build, repos):
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
307 config = BuildConfig.fetch(self.env, build.config)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
308
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
309 platform = TargetPlatform.fetch(self.env, build.platform)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
310 # Platform may or may not exist anymore - get safe name for logging
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
311 platform_name = platform and platform.name \
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
312 or 'unknown platform "%s"' % build.platform
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
313
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
314 # Drop build if platform no longer exists
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
315 if not platform:
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
316 self.log.info('Dropping build of configuration "%s" at '
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
317 'revision [%s] on %s because the platform no longer '
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
318 'exists', config.name, build.rev, platform_name)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
319 return True
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
320
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
321 # Ignore pending builds for deactived build configs
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
322 if not config.active:
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
323 self.log.info('Dropping build of configuration "%s" at '
513
90ec4de2df6b Check whether fetching `TargetPlatform` succeeds and adjust log appropriately. Fixes #310
dfraser
parents: 468
diff changeset
324 'revision [%s] on %s because the configuration is '
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
325 'deactivated', config.name, build.rev, platform_name)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
326 return True
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
327
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
328 # Stay within the revision limits of the build config
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
329 if (config.min_rev and repos.rev_older_than(build.rev,
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
330 config.min_rev)) \
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
331 or (config.max_rev and repos.rev_older_than(config.max_rev,
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
332 build.rev)):
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
333 self.log.info('Dropping build of configuration "%s" at revision [%s] on '
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
334 '"%s" because it is outside of the revision range of the '
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
335 'configuration', config.name, build.rev, platform_name)
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
336 return True
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
337
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
338 # If not 'build_all', drop if a more recent revision is available
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
339 if not self.build_all and \
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
340 len(list(Build.select(self.env, config=build.config,
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
341 min_rev_time=build.rev_time, platform=build.platform))) > 1:
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
342 self.log.info('Dropping build of configuration "%s" at revision [%s] '
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
343 'on "%s" because a more recent build exists',
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 585
diff changeset
344 config.name, build.rev, platform_name)
392
026d9aa41b85 Merged HTTP branch into trunk.
cmlenz
parents: 379
diff changeset
345 return True
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents:
diff changeset
346
253
cda723f3ac31 Provide hooks for build notification. Closes #62.
cmlenz
parents: 239
diff changeset
347 return False
Copyright (C) 2012-2017 Edgewall Software