Browse files

Allow rerunning a job from notifications.

  • Loading branch information...
1 parent 019d9da commit 7a8dc6b5218a53fb88463746483ea9679f6654b2 @buchuki buchuki committed Nov 25, 2010
View
13 greatbigcrane/job_queue/jobs.py
@@ -31,12 +31,18 @@
def queue_job(command, **kwargs):
'''Run the given command on the job queue, passing it any arguments as kwargs.'''
- assert command in command_map
- kwargs.update(command=command)
- serialized = json.dumps(kwargs)
+ serialized = make_job_string(command, **kwargs)
+ send_job(serialized)
+
+def send_job(serialized):
socket.send(serialized)
assert socket.recv() == "ACK"
+def make_job_string(command, **kwargs):
+ assert command in command_map
+ kwargs.update(command=command)
+ return json.dumps(kwargs)
+
def command(command_name):
"Decorator that marks a function as a queuable command."
def wrap(function):
@@ -173,6 +179,7 @@ def test_buildout(project_id):
project.name, "success" if not errors else "error"),
message=('\n\n'+'*'*50+'\n\n').join(message),
project=project,
+ rerun_job=make_job_string("TEST", project_id=project_id),
notification_type="TEST",
)
project.test_status = not errors
View
1 greatbigcrane/job_queue/urls.py
@@ -27,4 +27,5 @@
url('^(?P<project_id>\d+)/edit_buildout/$', 'edit_buildout', name="edit_buildout"),
url('^(?P<project_id>\d+)/virtualenv/$', 'schedule_virtualenv', name="schedule_virtualenv"),
url('^(?P<project_id>\d+)/pip_install/$', 'schedule_pip_install', name="schedule_pip_install"),
+ url('^rerun_job/(?P<notification_id>\d+)/$', 'rerun_job', name="rerun_job")
)
View
10 greatbigcrane/job_queue/views.py
@@ -2,8 +2,9 @@
from django.http import HttpResponse, HttpResponseServerError
from django.template import RequestContext
from project.models import Project
-from job_queue.jobs import queue_job
+from job_queue.jobs import queue_job, send_job
from job_queue.forms import StartAppForm
+from notifications.models import Notification
def schedule_buildout(request, project_id):
return schedule_project_command(request, project_id, "BUILDOUT",
@@ -51,6 +52,13 @@ def schedule_pip_install(request, project_id):
return schedule_project_command(request, project_id, "PIPINSTALL",
"Successfully queued pip_install")
+def rerun_job(request, notification_id):
+ notification = get_object_or_404(Notification, id=notification_id)
+ print notification.rerun_job
+ if notification.rerun_job:
+ send_job(str(notification.rerun_job))
+ return HttpResponse("Queued")
+ return HttpResponse("No rerun specified")
def schedule_project_command(request, project_id, command, success_message):
project = get_object_or_404(Project, id=project_id)
View
2 greatbigcrane/media/js/script.js
@@ -168,7 +168,7 @@ jQuery(function($){
});
$('.projects .buildout, .projects .tests').live('click',queue_button('closest', 'li'));
- $('.actions .ajax').live('click',queue_button('closest', 'div.project > section'));
+ $('.ajax').live('click',queue_button('closest', 'div.project > section'));
$('.confirm').live('click',function(e){
e.preventDefault();
if ( confirm("Are you sure you want to do this?") ) {
View
1 greatbigcrane/notifications/models.py
@@ -29,6 +29,7 @@ class Notification(models.Model):
project = models.ForeignKey(Project, null=True, blank=True, default=None)
notification_type = models.CharField(max_length=16, blank=True, default='')
dismissed = models.BooleanField(blank=True, default=False)
+ rerun_job = models.CharField(blank=True, max_length=128)
def get_absolute_url(self):
return reverse("view_notification", args=[self.id])
View
3 greatbigcrane/templates/notifications/notification.html
@@ -8,6 +8,9 @@
</span>
{% if notification.project %}
<a href="{% url view_project notification.project.id %}" class="button highlight left clear margin orange">View Project</a>
+ {% if notification.rerun_job %}
+ <a href="{% url rerun_job notification.id %}" class="button highlight left ajax margin orange">Rerun Job</a>
+ {% endif %}
{% endif %}
<code class="clear notification-code">{{notification.message}}</code>
</div>

0 comments on commit 7a8dc6b

Please sign in to comment.