Bug 1311840 - Bail if we try to run crossreference_error_lines on a job with an existing TextLogSummary (#1942)

This commit is contained in:
jgraham 2016-10-24 14:49:16 +01:00 коммит произвёл GitHub
Родитель 31434ff9c2
Коммит f769d2dbbc
2 изменённых файлов: 40 добавлений и 2 удалений

Просмотреть файл

@ -92,3 +92,26 @@ def test_crossreference_error_lines_missing(test_job):
assert summary_line.failure_line == failure_line
assert summary_line.verified is False
assert summary_line.bug_number is None
def test_crossreference_error_lines_repeat(test_job):
lines = [(test_line, {})]
create_failure_lines(test_job, lines)
create_text_log_errors(test_job, lines)
call_command('crossreference_error_lines', str(test_job.id))
failure_lines = FailureLine.objects.all()
summary_lines = TextLogSummaryLine.objects.all()
summary = TextLogSummary.objects.all()[0]
assert len(summary_lines) == 1
summary_line = summary_lines[0]
assert summary_line.summary == summary
assert summary_line.failure_line == failure_lines[0]
assert summary_line.verified is False
assert summary_line.bug_number is None
call_command('crossreference_error_lines', str(test_job.id))

Просмотреть файл

@ -1,6 +1,8 @@
import logging
import re
from django.db import (IntegrityError,
transaction)
from mozlog.formatters.tbplformatter import TbplFormatter
from treeherder.model.models import (FailureLine,
@ -21,6 +23,19 @@ def crossreference_job(job):
:job: - Job for which to perform the crossreferencing
"""
try:
return _crossreference(job)
except IntegrityError:
logger.warning("IntegrityError crossreferencing error lines for job %s" % job.id)
@transaction.atomic
def _crossreference(job):
if TextLogSummary.objects.filter(job_guid=job.guid).exists():
logger.info("crossreference_error_lines already ran for job %s" % job.id)
return
failure_lines = FailureLine.objects.filter(job_guid=job.guid)
text_log_errors = TextLogError.objects.filter(
@ -31,7 +46,7 @@ def crossreference_job(job):
if not (failure_lines.exists() and text_log_errors.exists()):
return []
summary, _ = TextLogSummary.objects.get_or_create(job_guid=job.guid,
summary = TextLogSummary.objects.create(job_guid=job.guid,
repository=job.repository)
match_iter = structured_iterator(failure_lines)