Code review comment for lp:~abentley/launchpad/jobstatus

Revision history for this message
Aaron Bentley (abentley) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Guilherme Salgado wrote:

>> === modified file 'lib/canonical/launchpad/icing/style.css'
>> --- lib/canonical/launchpad/icing/style.css 2009-12-08 10:57:44 +0000
>> +++ lib/canonical/launchpad/icing/style.css 2009-12-17 21:46:16 +0000
>> @@ -1104,7 +1104,7 @@
>> height: 2.5em;
>> }
>>
>> -#branch-pending-writes {
>> +#branch-pending-writes, #diff-pending-update {
>
> Is this not a good opportunity to rename this class to 'pending-update'
> or 'update-in-progress' instead of creating an alias to it?

Okay, I can do that.

>> background: #FFF59C;
>> width: 40em;
>> margin: 1em auto;
>> @@ -1117,7 +1117,7 @@
>> -webkit-border-radius: 5px;
>> }
>>
>> -#branch-pending-writes h3 {
>> +#branch-pending-writes h3, #diff-pending-update h3 {
>> color: black;
>> font-weight: bold;
>> text-align: center;
>>
>
>> === modified file 'lib/lp/code/interfaces/branchmergeproposal.py'
>> --- lib/lp/code/interfaces/branchmergeproposal.py 2009-10-23 00:48:47 +0000
>> +++ lib/lp/code/interfaces/branchmergeproposal.py 2009-12-17 21:46:16 +0000
>> @@ -155,6 +155,8 @@
>> IStaticDiff, title=_('The diff to be used for reviews.'),
>> readonly=True)
>>
>> + next_preview_diff_job = Attribute('foo')
>> +
>
> !?

Circular dependencies. I'll make the attribute somewhat better.

>> preview_diff = exported(
>> Reference(
>> IPreviewDiff,
>> @@ -511,6 +513,10 @@
>> class IBranchMergeProposalJob(Interface):
>> """A Job related to a Branch Merge Proposal."""
>>
>> + id = Int(
>> + title=_('DB ID'), required=True, readonly=True,
>> + description=_("Database id for this BranchJob."))
>
> Do you really need to expose this in the public interface or is it just
> for your test?

I think it makes a lot of sense to expose in the public interface, and I
have another branch in which it is necessary to expose it in the public
interface:

https://code.edge.launchpad.net/~abentley/launchpad/ampoulejob/+merge/15982

In this case, once I change the test to use an equality, I don't need it.

>
>> +
>> branch_merge_proposal = Object(
>> title=_('The BranchMergeProposal this job is about'),
>> schema=IBranchMergeProposal, required=True)
>>
>> === modified file 'lib/lp/code/model/branchmergeproposal.py'
>> --- lib/lp/code/model/branchmergeproposal.py 2009-12-01 01:09:38 +0000
>> +++ lib/lp/code/model/branchmergeproposal.py 2009-12-17 21:46:16 +0000
> [...]
>>
>>
>> def is_valid_transition(proposal, from_state, next_state, user=None):
>> @@ -132,6 +134,26 @@
>> review_diff = ForeignKey(
>> foreignKey='StaticDiff', notNull=False, default=None)
>>
>> + @property
>> + def next_preview_diff_job(self):
>> + from lp.code.model.branchmergeproposaljob import (
>> + BranchMergeProposalJob, MergeProposalCreatedJob,
>> + UpdatePreviewDiffJob)
>
> Circular dependencies?

Yes.

> If so, care to leave a comment here?

Alright.

>
>> + job_classes = [MergeProposalCreatedJob, UpdatePreviewDiffJob]
>> + type_classes = dict(
>> + (job_class.class_job_type, job_class)
>> + for job_class in job_classes)
>> + job = Store.of(self).find(
>> + BranchMergeProposalJob,
>> + BranchMergeProposalJob.job_type.is_in(type_classes),
>
> I think it'd be better to explicitly pass type_classes.keys() above, to
> not leave your reader wondering why a dict is being passed to is_in().

Okay.

>> === modified file 'lib/lp/code/model/branchmergeproposaljob.py'
>> --- lib/lp/code/model/branchmergeproposaljob.py 2009-11-03 21:05:14 +0000
>> +++ lib/lp/code/model/branchmergeproposaljob.py 2009-12-17 21:46:16 +0000
>> @@ -27,6 +27,7 @@
>> from storm.store import Store
>> from zope.component import getUtility
>> from zope.interface import classProvides, implements
>> +from zope.security.proxy import removeSecurityProxy
>>
>> from canonical.database.enumcol import EnumCol
>> from canonical.launchpad.database.message import MessageJob, MessageJobAction
>> @@ -151,7 +152,9 @@
>> self.context = job
>>
>> def __eq__(self, job):
>> - return (self.__class__ is job.__class__ and self.job == job.job)
>> + return (
>> + self.__class__ is removeSecurityProxy(job.__class__)
>> + and self.job == job.job)
>
> Why did you change this?

So that it would work when comparing a securityproxied object with an
unproxied object.

>
>>
>> def __ne__(self, job):
>> return not (self == job)
>>
>> === modified file 'lib/lp/code/model/tests/test_branchmergeproposals.py'
>> --- lib/lp/code/model/tests/test_branchmergeproposals.py 2009-12-01 01:09:38 +0000
>> +++ lib/lp/code/model/tests/test_branchmergeproposals.py 2009-12-17 21:46:16 +0000
>> @@ -13,6 +13,7 @@
>>
>> from pytz import UTC
>> from sqlobject import SQLObjectNotFound
>> +from storm.locals import Store
>> from zope.component import getUtility
>> import transaction
>> from zope.security.proxy import removeSecurityProxy
>> @@ -1828,5 +1829,26 @@
>> self.checkExampleMerge(bmp.preview_diff.text)
>>
>>
>> +class TestNextPreviewDiffJob(TestCaseWithFactory):
>> +
>> + layer = DatabaseFunctionalLayer
>> +
>> + def test_returns_bmp_job(self):
>> + bmp = self.factory.makeBranchMergeProposal()
>> + job = bmp.next_preview_diff_job
>> + self.assertEqual(bmp, job.branch_merge_proposal)
>> + self.assertIs(
>> + MergeProposalCreatedJob, removeSecurityProxy(job).__class__)
>> + job.start()
>> + self.assertEqual(job.id, bmp.next_preview_diff_job.id)
>
> Why do you compare them by ID here?

Hysterical raisins.

Updates made, diff attached.

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAksr448ACgkQ0F+nu1YWqI3B9ACffOi6cTu5+nE6XT0Bq6IosAGI
4FcAn03I7oSjPlKQagLDL/sOzu9+yAWE
=Cf/V
-----END PGP SIGNATURE-----

1=== modified file 'lib/canonical/launchpad/icing/style.css'
2--- lib/canonical/launchpad/icing/style.css 2009-12-14 20:08:29 +0000
3+++ lib/canonical/launchpad/icing/style.css 2009-12-18 19:52:27 +0000
4@@ -1104,7 +1104,7 @@
5 height: 2.5em;
6 }
7
8-#branch-pending-writes, #diff-pending-update {
9+.pending-update {
10 background: #FFF59C;
11 width: 40em;
12 margin: 1em auto;
13@@ -1117,7 +1117,7 @@
14 -webkit-border-radius: 5px;
15 }
16
17-#branch-pending-writes h3, #diff-pending-update h3 {
18+.pending-update h3{
19 color: black;
20 font-weight: bold;
21 text-align: center;
22
23=== modified file 'lib/lp/code/interfaces/branchmergeproposal.py'
24--- lib/lp/code/interfaces/branchmergeproposal.py 2009-12-18 14:51:37 +0000
25+++ lib/lp/code/interfaces/branchmergeproposal.py 2009-12-18 19:44:07 +0000
26@@ -118,7 +118,8 @@
27 IStaticDiff, title=_('The diff to be used for reviews.'),
28 readonly=True)
29
30- next_preview_diff_job = Attribute('foo')
31+ next_preview_diff_job = Attribute(
32+ 'The next BranchMergeProposalJob that will update a preview diff.')
33
34 preview_diff = exported(
35 Reference(
36@@ -476,10 +477,6 @@
37 class IBranchMergeProposalJob(Interface):
38 """A Job related to a Branch Merge Proposal."""
39
40- id = Int(
41- title=_('DB ID'), required=True, readonly=True,
42- description=_("Database id for this BranchJob."))
43-
44 branch_merge_proposal = Object(
45 title=_('The BranchMergeProposal this job is about'),
46 schema=IBranchMergeProposal, required=True)
47
48=== modified file 'lib/lp/code/model/branchmergeproposal.py'
49--- lib/lp/code/model/branchmergeproposal.py 2009-12-18 14:51:37 +0000
50+++ lib/lp/code/model/branchmergeproposal.py 2009-12-18 19:44:53 +0000
51@@ -137,6 +137,7 @@
52
53 @property
54 def next_preview_diff_job(self):
55+ # circular dependencies
56 from lp.code.model.branchmergeproposaljob import (
57 BranchMergeProposalJob, MergeProposalCreatedJob,
58 UpdatePreviewDiffJob)
59@@ -147,7 +148,7 @@
60 job = Store.of(self).find(
61 BranchMergeProposalJob,
62 BranchMergeProposalJob.branch_merge_proposal == self,
63- BranchMergeProposalJob.job_type.is_in(type_classes),
64+ BranchMergeProposalJob.job_type.is_in(type_classes.keys()),
65 BranchMergeProposalJob.job == Job.id,
66 Job._status.is_in([JobStatus.WAITING, JobStatus.RUNNING])
67 ).order_by(Job.scheduled_start, Job.date_created).first()
68
69=== modified file 'lib/lp/code/model/tests/test_branchmergeproposals.py'
70--- lib/lp/code/model/tests/test_branchmergeproposals.py 2009-12-18 14:51:37 +0000
71+++ lib/lp/code/model/tests/test_branchmergeproposals.py 2009-12-18 19:41:47 +0000
72@@ -1879,9 +1879,9 @@
73 """Jobs are shown while pending."""
74 bmp = self.factory.makeBranchMergeProposal()
75 job = bmp.next_preview_diff_job
76- self.assertEqual(job.id, bmp.next_preview_diff_job.id)
77+ self.assertEqual(job, bmp.next_preview_diff_job)
78 job.start()
79- self.assertEqual(job.id, bmp.next_preview_diff_job.id)
80+ self.assertEqual(job, bmp.next_preview_diff_job)
81 job.fail()
82 self.assertIs(None, bmp.next_preview_diff_job)
83
84
85=== modified file 'lib/lp/code/templates/branch-index.pt'
86--- lib/lp/code/templates/branch-index.pt 2009-12-03 18:33:22 +0000
87+++ lib/lp/code/templates/branch-index.pt 2009-12-18 19:49:08 +0000
88@@ -162,7 +162,7 @@
89
90 <div class="yui-g" tal:condition="view/pending_writes">
91 <div class="portlet">
92- <div id="branch-pending-writes">
93+ <div id="branch-pending-writes" class="pending-update">
94 <h3>Updating branch...</h3>
95 <p>
96 Launchpad is processing new changes to this branch and will be
97
98=== modified file 'lib/lp/code/templates/branchmergeproposal-index.pt'
99--- lib/lp/code/templates/branchmergeproposal-index.pt 2009-12-14 20:08:29 +0000
100+++ lib/lp/code/templates/branchmergeproposal-index.pt 2009-12-18 19:53:27 +0000
101@@ -181,7 +181,7 @@
102 </div>
103
104 <div class="yui-g" tal:condition="view/pending_diff">
105- <div class="portlet" id="diff-pending-update">
106+ <div class="portlet pending-update" id="diff-pending-update">
107 <h3>Updating diff...</h3>
108 <p>
109 An updated diff will be available in a few minutes. Reload to see the

« Back to merge proposal