launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #05045
[Merge] lp:~allenap/launchpad/longpoll-merge-diff-event into lp:launchpad
Gavin Panella has proposed merging lp:~allenap/launchpad/longpoll-merge-diff-event into lp:launchpad with lp:~allenap/launchpad/longpoll-storm-events-subscribe as a prerequisite.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~allenap/launchpad/longpoll-merge-diff-event/+merge/76407
This changes UpdatePreviewDiffJob to issue an ObjectModifiedEvent when
it updates the preview_diff. That's it!
--
https://code.launchpad.net/~allenap/launchpad/longpoll-merge-diff-event/+merge/76407
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/launchpad/longpoll-merge-diff-event into lp:launchpad.
=== modified file 'lib/lp/code/model/branchmergeproposaljob.py'
--- lib/lp/code/model/branchmergeproposaljob.py 2011-07-04 15:48:18 +0000
+++ lib/lp/code/model/branchmergeproposaljob.py 2011-09-21 13:21:32 +0000
@@ -38,6 +38,8 @@
DBEnumeratedType,
DBItem,
)
+from lazr.lifecycle.event import ObjectModifiedEvent
+from lazr.lifecycle.snapshot import Snapshot
import pytz
import simplejson
from sqlobject import SQLObjectNotFound
@@ -54,6 +56,7 @@
)
from storm.store import Store
from zope.component import getUtility
+from zope.event import notify
from zope.interface import (
classProvides,
implements,
@@ -61,11 +64,6 @@
from canonical.config import config
from canonical.database.enumcol import EnumCol
-from lp.services.messages.model.message import (
- MessageJob,
- MessageJobAction,
- )
-from lp.services.messages.interfaces.message import IMessageJob
from canonical.launchpad.webapp import errorlog
from canonical.launchpad.webapp.interaction import setupInteraction
from canonical.launchpad.webapp.interfaces import (
@@ -105,6 +103,7 @@
get_rw_server,
)
from lp.registry.interfaces.person import IPersonSet
+from lp.services.database.stormbase import StormBase
from lp.services.job.interfaces.job import JobStatus
from lp.services.job.model.job import Job
from lp.services.job.runner import (
@@ -112,7 +111,11 @@
BaseRunnableJobSource,
)
from lp.services.mail.sendmail import format_address_for_person
-from lp.services.database.stormbase import StormBase
+from lp.services.messages.interfaces.message import IMessageJob
+from lp.services.messages.model.message import (
+ MessageJob,
+ MessageJobAction,
+ )
class BranchMergeProposalJobType(DBEnumeratedType):
@@ -376,7 +379,13 @@
self.checkReady()
preview = PreviewDiff.fromBranchMergeProposal(
self.branch_merge_proposal)
+ branch_merge_proposal_snapshot = Snapshot(
+ self.branch_merge_proposal, names=["preview_diff"])
self.branch_merge_proposal.preview_diff = preview
+ modified_event = ObjectModifiedEvent(
+ self.branch_merge_proposal, branch_merge_proposal_snapshot,
+ vars(branch_merge_proposal_snapshot).keys())
+ notify(modified_event)
def getOperationDescription(self):
return ('generating the diff for a merge proposal')
=== modified file 'lib/lp/code/model/tests/test_branchmergeproposaljobs.py'
--- lib/lp/code/model/tests/test_branchmergeproposaljobs.py 2011-08-12 11:37:08 +0000
+++ lib/lp/code/model/tests/test_branchmergeproposaljobs.py 2011-09-21 13:21:32 +0000
@@ -11,6 +11,7 @@
)
from lazr.lifecycle.event import ObjectModifiedEvent
+from lazr.lifecycle.events import IObjectModifiedEvent
import pytz
from sqlobject import SQLObjectNotFound
from storm.locals import Select
@@ -60,7 +61,10 @@
from lp.services.job.model.job import Job
from lp.services.job.runner import JobRunner
from lp.services.osutils import override_environ
-from lp.testing import TestCaseWithFactory
+from lp.testing import (
+ EventRecorder,
+ TestCaseWithFactory,
+ )
from lp.testing.mail_helpers import pop_notifications
@@ -203,9 +207,21 @@
bmp.source_branch.next_mirror_time = None
transaction.commit()
self.layer.switchDbUser(config.merge_proposal_jobs.dbuser)
- JobRunner([job]).runAll()
- transaction.commit()
+ with EventRecorder() as event_recorder:
+ JobRunner([job]).runAll()
+ transaction.commit()
self.checkExampleMerge(bmp.preview_diff.text)
+ # A single IObjectModifiedEvent is issued when the preview diff has
+ # been calculated.
+ bmp_object_events = [
+ event for event in event_recorder.events
+ if (IObjectModifiedEvent.providedBy(event) and
+ event.object == bmp)]
+ self.assertEqual(
+ 1, len(bmp_object_events),
+ "Expected one event, got: %r" % bmp_object_events)
+ self.assertEqual(
+ ["preview_diff"], bmp_object_events[0].edited_fields)
def test_run_branches_not_ready(self):
# If the job has been waiting for a significant period of time (15
=== modified file 'lib/lp/services/job/configure.zcml'
--- lib/lp/services/job/configure.zcml 2011-07-05 09:01:53 +0000
+++ lib/lp/services/job/configure.zcml 2011-09-21 13:21:32 +0000
@@ -11,4 +11,3 @@
<allow interface=".interfaces.job.IJob" />
</class>
</configure>
-
=== modified file 'lib/lp/services/messaging/queue.py'
--- lib/lp/services/messaging/queue.py 2011-07-05 09:01:53 +0000
+++ lib/lp/services/messaging/queue.py 2011-09-21 13:21:32 +0000
@@ -23,6 +23,7 @@
EmptyQueueException,
)
+
LAUNCHPAD_EXCHANGE = "launchpad-exchange"
@@ -187,4 +188,3 @@
self.channel.basic_consume(self.name, callback=callback)
self.channel.wait()
return result[0]
-