~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/buildmaster/model/buildqueue.py

  • Committer: Steve Kowalik
  • Date: 2011-08-07 04:05:52 UTC
  • mto: This revision was merged to the branch mainline in revision 13626.
  • Revision ID: stevenk@ubuntu.com-20110807040552-mwnxo0flmhvl35e8
Correct the notification based on review comments, and remove request{,ed}
from the function names, switching to create{,d}.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
# pylint: disable-msg=E0611,W0212
16
16
    datetime,
17
17
    timedelta,
18
18
    )
19
 
from itertools import groupby
20
19
import logging
21
 
from operator import attrgetter
22
20
 
23
21
import pytz
24
22
from sqlobject import (
35
33
    )
36
34
from zope.interface import implements
37
35
 
 
36
from canonical.database.constants import DEFAULT
 
37
from canonical.database.enumcol import EnumCol
 
38
from canonical.database.sqlbase import (
 
39
    SQLBase,
 
40
    sqlvalues,
 
41
    )
 
42
from canonical.launchpad.webapp.interfaces import (
 
43
    DEFAULT_FLAVOR,
 
44
    IStoreSelector,
 
45
    MAIN_STORE,
 
46
    )
38
47
from lp.app.errors import NotFoundError
39
48
from lp.buildmaster.enums import BuildFarmJobType
40
 
from lp.buildmaster.interfaces.buildfarmjob import IBuildFarmJob
 
49
from lp.buildmaster.interfaces.buildfarmjob import (
 
50
    IBuildFarmJob,
 
51
    )
41
52
from lp.buildmaster.interfaces.buildfarmjobbehavior import (
42
53
    IBuildFarmJobBehavior,
43
54
    )
45
56
    IBuildQueue,
46
57
    IBuildQueueSet,
47
58
    )
48
 
from lp.services.database.constants import DEFAULT
49
 
from lp.services.database.enumcol import EnumCol
50
 
from lp.services.database.sqlbase import (
51
 
    SQLBase,
52
 
    sqlvalues,
53
 
    )
54
59
from lp.services.job.interfaces.job import JobStatus
55
60
from lp.services.job.model.job import Job
56
 
from lp.services.webapp.interfaces import (
57
 
    DEFAULT_FLAVOR,
58
 
    IStoreSelector,
59
 
    MAIN_STORE,
60
 
    )
61
61
 
62
62
 
63
63
def normalize_virtualization(virtualized):
144
144
        specific_class = specific_job_classes()[self.job_type]
145
145
        return specific_class.getByJob(self.job)
146
146
 
147
 
    @staticmethod
148
 
    def preloadSpecificJobData(queues):
149
 
        key = attrgetter('job_type')
150
 
        for job_type, grouped_queues in groupby(queues, key=key):
151
 
            specific_class = specific_job_classes()[job_type]
152
 
            queue_subset = list(grouped_queues)
153
 
            # We need to preload the build farm jobs early to avoid
154
 
            # the call to _set_build_farm_job to look up BuildFarmBuildJobs
155
 
            # one by one.
156
 
            specific_class.preloadBuildFarmJobs(queue_subset)
157
 
            specific_jobs = specific_class.getByJobs(queue_subset)
158
 
            if len(list(specific_jobs)) == 0:
159
 
                continue
160
 
            specific_class.preloadJobsData(specific_jobs)
161
 
 
162
147
    @property
163
148
    def date_started(self):
164
149
        """See `IBuildQueue`."""
224
209
        self.logtail = None
225
210
        self.specific_job.jobReset()
226
211
 
227
 
    def cancel(self):
228
 
        """See `IBuildQueue`."""
229
 
        self.specific_job.jobCancel()
230
 
        self.destroySelf()
231
 
 
232
212
    def setDateStarted(self, timestamp):
233
213
        """See `IBuildQueue`."""
234
214
        self.job.date_started = timestamp
478
458
            # the delays should be averaged/divided by the number of jobs.
479
459
            denominator = (jobs if jobs < builders else builders)
480
460
            if denominator > 1:
481
 
                duration = int(duration / float(denominator))
 
461
                duration = int(duration/float(denominator))
482
462
 
483
463
            sum_of_delays += duration
484
464