From 0a4ec98c42e1949a6dbd201310c0277737d38411 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Michel=20Nirgal=20Vourg=C3=A8re?= Date: Sat, 13 Nov 2010 01:20:18 +0000 Subject: [PATCH] Fixed job detail crash when running job is killed Added notify field to job table: Only notify about finished job when "too slow" was displayed. --- bin/djais/models.py | 1 + bin/djais/views.py | 3 +++ bin/jobrunner.py | 11 +++++++++-- html_templates/job.html | 29 +++++++++++++++++------------ structure.sql | 3 ++- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/bin/djais/models.py b/bin/djais/models.py index ebdc864..e73ff49 100644 --- a/bin/djais/models.py +++ b/bin/djais/models.py @@ -218,6 +218,7 @@ class Job(models.Model): pid = models.IntegerField(blank=True, null=True) result = models.IntegerField(blank=True, null=True) archive_time = models.DateTimeField(blank=True, null=True) + notify = models.CharField(max_length=1, blank=True, null=True) def queue_rank(self): return Job.objects.filter(queue_time__lt=self.queue_time).filter(start_time__isnull=True).count() + 1 diff --git a/bin/djais/views.py b/bin/djais/views.py index 82b0d2e..a2eec22 100644 --- a/bin/djais/views.py +++ b/bin/djais/views.py @@ -775,6 +775,9 @@ def job_get(request, jobid): total_wait += 1 if total_wait > 15: request.user.info('Your query is slow. Please be patient.') + if not job.notify: + job.notify = 'W' # Web + job.save() return HttpResponseRedirect('/job/%s/' % job.id) job = get_object_or_404(Job, id=jobid) diff --git a/bin/jobrunner.py b/bin/jobrunner.py index ab78eb9..31b4937 100755 --- a/bin/jobrunner.py +++ b/bin/jobrunner.py @@ -98,8 +98,15 @@ def runjob(): dbcommit() logging.info('Job complete: result=%s', returncode) - sqlexec(u"INSERT INTO user_message (user_id, user_message_category_id, txt) VALUES(%(user_id)s, 'info', %(msg)s)", {'user_id':user_id, 'msg':('Your job %(jobid)s is complete.' % {'jobid': jobid}) }) - dbcommit() + sqlexec(u'SELECT notify FROM job where id=%(jobid)s', {'jobid': jobid}) + row = get_common_cursor().fetchone() + if row: + notify = row[0] + if notify == u'W': + sqlexec(u"INSERT INTO user_message (user_id, user_message_category_id, txt) VALUES(%(user_id)s, 'info', %(msg)s)", {'user_id':user_id, 'msg':('Your job %(jobid)s is complete.' % {'jobid': jobid}) }) + sqlexec(u'UPDATE job SET notify=NULL WHERE id=%(jobid)s', {'jobid': jobid}) + dbcommit() + # else SMS, Mail ... return True diff --git a/html_templates/job.html b/html_templates/job.html index 6300602..a1c2fd8 100644 --- a/html_templates/job.html +++ b/html_templates/job.html @@ -18,18 +18,23 @@ Result size: {{ job.get_sucess_size|filesizeformat }}
{% if job.start_time %} Status: Running since {{ job.start_time|date:"Y-m-d H:i:s" }} UTC ( {{ job.running_time}} )
{% with job.get_stats as stats %} - Process ID: {{ stats.pid }}
- CPU ID: {{ stats.processor }}
- Nice: {{ stats.nice }}
- State: {{ stats.state }}
- Virtual size: {{ stats.vsize|filesizeformat }}
- {% comment %} - TODO: - "getconf CLK_TCK" = 100 -> 1 tick = 1/100 seconds - see Job.get_stat - {% endcomment %} - Time spent scheduled in user mode: {{ stats.utime }}00 ms
- Time spent scheduled in system mode: {{ stats.stime }}00 ms
+ {% if stats %} + Process ID: {{ stats.pid }}
+ CPU ID: {{ stats.processor }}
+ Nice: {{ stats.nice }}
+ State: {{ stats.state }}
+ Virtual size: {{ stats.vsize|filesizeformat }}
+ {% comment %} + TODO: + "getconf CLK_TCK" = 100 -> 1 tick = 1/100 seconds + see Job.get_stat + {% endcomment %} + Time spent scheduled in user mode: {{ stats.utime }}00 ms
+ Time spent scheduled in system mode: {{ stats.stime }}00 ms
+ {% else %} + Internal error: process {{ job.pid }} stats are not available.
+ Job runner daemon may be restarting now.... + {% endif %} {% endwith %} {% else %} Status: Queued since {{ job.queue_time }}.
diff --git a/structure.sql b/structure.sql index 01218e6..2e8c6f0 100644 --- a/structure.sql +++ b/structure.sql @@ -116,7 +116,8 @@ CREATE TABLE job ( pid integer, result integer, archive_time timestamp without time zone, - friendly_filename character varying(255) NOT NULL + friendly_filename character varying(255) NOT NULL, + notify character varying(1) ); -- 2.30.2