Merge lp:~lifeless/launchpad/bugjob into lp:launchpad

Proposed by Robert Collins on 2012-03-04
Status: Merged
Approved by: Robert Collins on 2012-03-04
Approved revision: no longer in the source branch.
Merged at revision: 14900
Proposed branch: lp:~lifeless/launchpad/bugjob
Merge into: lp:launchpad
Diff against target: 319 lines (+2/-274)
5 files modified
database/schema/comments.sql (+0/-6)
lib/lp/bugs/interfaces/bugjob.py (+0/-68)
lib/lp/bugs/model/bugjob.py (+0/-147)
lib/lp/bugs/tests/test_bugjob.py (+0/-51)
lib/lp/soyuz/model/archivejob.py (+2/-2)
To merge this branch: bzr merge lp:~lifeless/launchpad/bugjob
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve on 2012-03-04
Review via email: mp+95773@code.launchpad.net

Commit Message

[r=lifeless][bug=946164] Remove the python code for BugJob as it is no longer used.

Description of the Change

Dead code is dead.

To post a comment you must log in.
Robert Collins (lifeless) wrote :

Trivial, self-ack.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/comments.sql'
2--- database/schema/comments.sql 2012-02-24 04:29:13 +0000
3+++ database/schema/comments.sql 2012-03-04 10:01:33 +0000
4@@ -225,12 +225,6 @@
5 COMMENT ON COLUMN BugBranch.whiteboard IS 'Additional information about the status of the bugfix in this branch.';
6 COMMENT ON COLUMN BugBranch.registrant IS 'The person who linked the bug to the branch.';
7
8--- BugJob
9-COMMENT ON TABLE BugJob IS 'Contains references to jobs to be run against Bugs.';
10-COMMENT ON COLUMN BugJob.bug IS 'The bug on which the job is to be run.';
11-COMMENT ON COLUMN BugJob.job_type IS 'The type of job (enumeration value). Allows us to query the database for a given subset of BugJobs.';
12-COMMENT ON COLUMN BugJob.json_data IS 'A JSON struct containing data for the job.';
13-
14 -- BugMute
15 COMMENT ON TABLE BugMute IS 'Mutes for bug notifications.';
16 COMMENT ON COLUMN BugMute.person IS 'The person that muted all notifications from this bug.';
17
18=== removed file 'lib/lp/bugs/interfaces/bugjob.py'
19--- lib/lp/bugs/interfaces/bugjob.py 2011-12-24 16:54:44 +0000
20+++ lib/lp/bugs/interfaces/bugjob.py 1970-01-01 00:00:00 +0000
21@@ -1,68 +0,0 @@
22-# Copyright 2010 Canonical Ltd. This software is licensed under the
23-# GNU Affero General Public License version 3 (see the file LICENSE).
24-
25-"""Interfaces for using the Jobs system for Bugs."""
26-
27-__metaclass__ = type
28-__all__ = [
29- 'BugJobType',
30- 'IBugJob',
31- 'IBugJobSource',
32- ]
33-
34-from lazr.enum import (
35- DBEnumeratedType,
36- DBItem,
37- )
38-from zope.interface import (
39- Attribute,
40- Interface,
41- )
42-from zope.schema import (
43- Int,
44- Object,
45- )
46-
47-from lp import _
48-from lp.bugs.interfaces.bug import IBug
49-from lp.services.job.interfaces.job import (
50- IJob,
51- IJobSource,
52- )
53-
54-
55-class BugJobType(DBEnumeratedType):
56- """Values that IBugJob.job_type can take."""
57-
58- UPDATE_HEAT = DBItem(0, """
59- Update the heat for a bug.
60-
61- This job recalculates the heat for a Bug.
62- """)
63-
64-
65-class IBugJob(Interface):
66- """A Job related to a Bug."""
67-
68- id = Int(
69- title=_('DB ID'), required=True, readonly=True,
70- description=_("The tracking number for this job."))
71-
72- bug = Object(
73- title=_('The Bug this job is about'),
74- schema=IBug, required=True)
75-
76- job = Object(title=_('The common Job attributes'), schema=IJob,
77- required=True)
78-
79- metadata = Attribute('A dict of data about the job.')
80-
81- def destroySelf():
82- """Destroy this object."""
83-
84-
85-class IBugJobSource(IJobSource):
86- """An interface for acquiring IBugJobs."""
87-
88- def create(bug):
89- """Create a new IBugJob for a bug."""
90
91=== removed file 'lib/lp/bugs/model/bugjob.py'
92--- lib/lp/bugs/model/bugjob.py 2011-12-30 06:14:56 +0000
93+++ lib/lp/bugs/model/bugjob.py 1970-01-01 00:00:00 +0000
94@@ -1,147 +0,0 @@
95-# Copyright 2010 Canonical Ltd. This software is licensed under the
96-# GNU Affero General Public License version 3 (see the file LICENSE).
97-
98-"""Job classes related to BugJobs are in here."""
99-
100-__metaclass__ = type
101-__all__ = [
102- 'BugJob',
103- 'BugJobDerived',
104- ]
105-
106-from lazr.delegates import delegates
107-import simplejson
108-from sqlobject import SQLObjectNotFound
109-from storm.expr import And
110-from storm.locals import (
111- Int,
112- Reference,
113- Unicode,
114- )
115-from zope.component import getUtility
116-from zope.interface import (
117- classProvides,
118- implements,
119- )
120-
121-from lp.bugs.interfaces.bugjob import (
122- BugJobType,
123- IBugJob,
124- IBugJobSource,
125- )
126-from lp.bugs.model.bug import Bug
127-from lp.services.database.enumcol import EnumCol
128-from lp.services.database.stormbase import StormBase
129-from lp.services.job.model.job import Job
130-from lp.services.job.runner import BaseRunnableJob
131-from lp.services.webapp.interfaces import (
132- DEFAULT_FLAVOR,
133- IStoreSelector,
134- MAIN_STORE,
135- MASTER_FLAVOR,
136- )
137-
138-
139-class BugJob(StormBase):
140- """Base class for jobs related to Bugs."""
141-
142- implements(IBugJob)
143-
144- __storm_table__ = 'BugJob'
145-
146- id = Int(primary=True)
147-
148- job_id = Int(name='job')
149- job = Reference(job_id, Job.id)
150-
151- bug_id = Int(name='bug')
152- bug = Reference(bug_id, Bug.id)
153-
154- job_type = EnumCol(enum=BugJobType, notNull=True)
155-
156- _json_data = Unicode('json_data')
157-
158- @property
159- def metadata(self):
160- return simplejson.loads(self._json_data)
161-
162- def __init__(self, bug, job_type, metadata):
163- """Constructor.
164-
165- :param bug: The proposal this job relates to.
166- :param job_type: The BugJobType of this job.
167- :param metadata: The type-specific variables, as a JSON-compatible
168- dict.
169- """
170- super(BugJob, self).__init__()
171- json_data = simplejson.dumps(metadata)
172- self.job = Job()
173- self.bug = bug
174- self.job_type = job_type
175- # XXX AaronBentley 2009-01-29 bug=322819: This should be a bytestring,
176- # but the DB representation is unicode.
177- self._json_data = json_data.decode('utf-8')
178-
179- @classmethod
180- def get(cls, key):
181- """Return the instance of this class whose key is supplied."""
182- store = getUtility(IStoreSelector).get(MAIN_STORE, DEFAULT_FLAVOR)
183- instance = store.get(cls, key)
184- if instance is None:
185- raise SQLObjectNotFound(
186- 'No occurrence of %s has key %s' % (cls.__name__, key))
187- return instance
188-
189-
190-class BugJobDerived(BaseRunnableJob):
191- """Intermediate class for deriving from BugJob."""
192- delegates(IBugJob)
193- classProvides(IBugJobSource)
194-
195- def __init__(self, job):
196- self.context = job
197-
198- @classmethod
199- def create(cls, bug):
200- """See `IBugJob`."""
201- # If there's already a job for the bug, don't create a new one.
202- job = BugJob(bug, cls.class_job_type, {})
203- return cls(job)
204-
205- @classmethod
206- def get(cls, job_id):
207- """Get a job by id.
208-
209- :return: the BugJob with the specified id, as the current
210- BugJobDerived subclass.
211- :raises: SQLObjectNotFound if there is no job with the specified id,
212- or its job_type does not match the desired subclass.
213- """
214- job = BugJob.get(job_id)
215- if job.job_type != cls.class_job_type:
216- raise SQLObjectNotFound(
217- 'No object found with id %d and type %s' % (job_id,
218- cls.class_job_type.title))
219- return cls(job)
220-
221- @classmethod
222- def iterReady(cls):
223- """Iterate through all ready BugJobs."""
224- store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR)
225- jobs = store.find(
226- BugJob,
227- And(BugJob.job_type == cls.class_job_type,
228- BugJob.job == Job.id,
229- Job.id.is_in(Job.ready_jobs),
230- BugJob.bug == Bug.id))
231- return (cls(job) for job in jobs)
232-
233- def getOopsVars(self):
234- """See `IRunnableJob`."""
235- vars = BaseRunnableJob.getOopsVars(self)
236- vars.extend([
237- ('bug_id', self.context.bug.id),
238- ('bug_job_id', self.context.id),
239- ('bug_job_type', self.context.job_type.title),
240- ])
241- return vars
242
243=== removed file 'lib/lp/bugs/tests/test_bugjob.py'
244--- lib/lp/bugs/tests/test_bugjob.py 2012-01-01 02:58:52 +0000
245+++ lib/lp/bugs/tests/test_bugjob.py 1970-01-01 00:00:00 +0000
246@@ -1,51 +0,0 @@
247-# Copyright 2010 Canonical Ltd. This software is licensed under the
248-# GNU Affero General Public License version 3 (see the file LICENSE).
249-
250-"""Tests for BugJobs."""
251-
252-__metaclass__ = type
253-
254-from lp.bugs.interfaces.bugjob import BugJobType
255-from lp.bugs.model.bugjob import (
256- BugJob,
257- BugJobDerived,
258- )
259-from lp.testing import TestCaseWithFactory
260-from lp.testing.layers import LaunchpadZopelessLayer
261-
262-
263-class BugJobTestCase(TestCaseWithFactory):
264- """Test case for basic BugJob gubbins."""
265-
266- layer = LaunchpadZopelessLayer
267-
268- def test_instantiate(self):
269- # BugJob.__init__() instantiates a BugJob instance.
270- bug = self.factory.makeBug()
271-
272- metadata = ('some', 'arbitrary', 'metadata')
273- bug_job = BugJob(
274- bug, BugJobType.UPDATE_HEAT, metadata)
275-
276- self.assertEqual(bug, bug_job.bug)
277- self.assertEqual(BugJobType.UPDATE_HEAT, bug_job.job_type)
278-
279- # When we actually access the BugJob's metadata it gets
280- # unserialized from JSON, so the representation returned by
281- # bug_heat.metadata will be different from what we originally
282- # passed in.
283- metadata_expected = [u'some', u'arbitrary', u'metadata']
284- self.assertEqual(metadata_expected, bug_job.metadata)
285-
286-
287-class BugJobDerivedTestCase(TestCaseWithFactory):
288- """Test case for the BugJobDerived class."""
289-
290- layer = LaunchpadZopelessLayer
291-
292- def test_create_explodes(self):
293- # BugJobDerived.create() will blow up because it needs to be
294- # subclassed to work properly.
295- bug = self.factory.makeBug()
296- self.assertRaises(
297- AttributeError, BugJobDerived.create, bug)
298
299=== modified file 'lib/lp/soyuz/model/archivejob.py'
300--- lib/lp/soyuz/model/archivejob.py 2011-12-30 06:14:56 +0000
301+++ lib/lp/soyuz/model/archivejob.py 2012-03-04 10:01:33 +0000
302@@ -108,7 +108,7 @@
303 """Get a job by id.
304
305 :return: the ArchiveJob with the specified id, as the current
306- BugJobDerived subclass.
307+ ArchiveJobDerived subclass.
308 :raises: SQLObjectNotFound if there is no job with the specified id,
309 or its job_type does not match the desired subclass.
310 """
311@@ -121,7 +121,7 @@
312
313 @classmethod
314 def iterReady(cls):
315- """Iterate through all ready BugJobs."""
316+ """Iterate through all ready ArchiveJobs."""
317 store = getUtility(IStoreSelector).get(MAIN_STORE, MASTER_FLAVOR)
318 jobs = store.find(
319 ArchiveJob,