Merge lp:~mwhudson/lava-scheduler/job-signals into lp:lava-scheduler

Proposed by Michael Hudson-Doyle
Status: Rejected
Rejected by: Michael Hudson-Doyle
Proposed branch: lp:~mwhudson/lava-scheduler/job-signals
Merge into: lp:lava-scheduler
Diff against target: 40 lines (+13/-1)
2 files modified
lava_scheduler_app/models.py (+9/-1)
lava_scheduler_app/signals.py (+4/-0)
To merge this branch: bzr merge lp:~mwhudson/lava-scheduler/job-signals
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Approve
Review via email: mp+92162@code.launchpad.net

Description of the change

We talked about this yesterday and I think it's OK, but I was tired then and tired now and can't really remember :-)

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

+1 :-)

review: Approve
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Unfortunately, it turns out to be a bit more complicated: all the queries need to be changed if _status is the name of the field.

I think some approach of saving the initial value in __init__ and firing the signal in save() if it has changed might work better. Will try that later/tomorrow.

Unmerged revisions

126. By Michael Hudson-Doyle

add a job_status_changed signal

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lava_scheduler_app/models.py'
--- lava_scheduler_app/models.py 2012-02-08 22:05:30 +0000
+++ lava_scheduler_app/models.py 2012-02-08 23:36:49 +0000
@@ -6,6 +6,8 @@
66
7from linaro_django_xmlrpc.models import AuthToken7from linaro_django_xmlrpc.models import AuthToken
88
9from lava_scheduler_app.signals import job_status_changed
10
9class JSONDataError(ValueError):11class JSONDataError(ValueError):
10 """Error raised when JSON is syntactically valid but ill-formed."""12 """Error raised when JSON is syntactically valid but ill-formed."""
1113
@@ -182,11 +184,17 @@
182 blank = True,184 blank = True,
183 editable = False185 editable = False
184 )186 )
185 status = models.IntegerField(187 _status = models.IntegerField(
186 choices = STATUS_CHOICES,188 choices = STATUS_CHOICES,
187 default = SUBMITTED,189 default = SUBMITTED,
188 verbose_name = _(u"Status"),190 verbose_name = _(u"Status"),
191 db_column = 'status',
189 )192 )
193 def _set_status(self, new_status):
194 job_status_changed.send_robust(sender=self, new_status=new_status, old_status=self.status)
195 self._status = new_status
196 status = property(lambda x:x._status, _set_status)
197 del _set_status
190 definition = models.TextField(198 definition = models.TextField(
191 editable = False,199 editable = False,
192 )200 )
193201
=== added file 'lava_scheduler_app/signals.py'
--- lava_scheduler_app/signals.py 1970-01-01 00:00:00 +0000
+++ lava_scheduler_app/signals.py 2012-02-08 23:36:49 +0000
@@ -0,0 +1,4 @@
1import django.dispatch
2
3job_status_changed = django.dispatch.Signal(
4 providing_args=["job", "old_status", "new_status"])

Subscribers

People subscribed via source and target branches