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
1=== modified file 'lava_scheduler_app/models.py'
2--- lava_scheduler_app/models.py 2012-02-08 22:05:30 +0000
3+++ lava_scheduler_app/models.py 2012-02-08 23:36:49 +0000
4@@ -6,6 +6,8 @@
5
6 from linaro_django_xmlrpc.models import AuthToken
7
8+from lava_scheduler_app.signals import job_status_changed
9+
10 class JSONDataError(ValueError):
11 """Error raised when JSON is syntactically valid but ill-formed."""
12
13@@ -182,11 +184,17 @@
14 blank = True,
15 editable = False
16 )
17- status = models.IntegerField(
18+ _status = models.IntegerField(
19 choices = STATUS_CHOICES,
20 default = SUBMITTED,
21 verbose_name = _(u"Status"),
22+ db_column = 'status',
23 )
24+ def _set_status(self, new_status):
25+ job_status_changed.send_robust(sender=self, new_status=new_status, old_status=self.status)
26+ self._status = new_status
27+ status = property(lambda x:x._status, _set_status)
28+ del _set_status
29 definition = models.TextField(
30 editable = False,
31 )
32
33=== added file 'lava_scheduler_app/signals.py'
34--- lava_scheduler_app/signals.py 1970-01-01 00:00:00 +0000
35+++ lava_scheduler_app/signals.py 2012-02-08 23:36:49 +0000
36@@ -0,0 +1,4 @@
37+import django.dispatch
38+
39+job_status_changed = django.dispatch.Signal(
40+ providing_args=["job", "old_status", "new_status"])

Subscribers

People subscribed via source and target branches