Skip to content

Commit

Permalink
Merge pull request #539 from guidow/fix_logs_in_error_mail
Browse files Browse the repository at this point in the history
Fix the display of logs in error mails
  • Loading branch information
guidow committed Sep 25, 2015
2 parents 2262dfd + c03c8be commit 0f2bab2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pyfarm/scheduler/etc/scheduler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ failed_body:
{{ job.output_link }}
{% endif %}

{% if failed_logs %}
{% if failed_log_urls %}
Log(s) for failed tasks:
{% for log in failed_logs %}
{{log.url}}
{% for url in failed_log_urls %}
{{url}}
{% endfor%}
{% endif %}

Expand Down
17 changes: 9 additions & 8 deletions pyfarm/scheduler/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,22 +716,23 @@ def send_job_completion_mail(job_id, successful=True):
job.url+= "jobs/%s" % job.id

failed_tasks = Task.query.filter(Task.job == job,
Task.state == WorkState.FAILED)
failed_logs = []
Task.state == WorkState.FAILED).\
order_by(desc(Task.frame))
failed_log_urls = []
for task in failed_tasks:
last_log_assoc = TaskTaskLogAssociation.query.filter_by(
task=task).order_by(desc(
TaskTaskLogAssociation.attempt)).limit(1).first()
if last_log_assoc:
log = last_log_assoc.log
log.url = BASE_URL
if log.url[-1] != "/":
log.url += "/"
log.url += ("api/v1/jobs/%s/tasks/%s/attempts/%s/"
log_url = BASE_URL
if not log_url.endswith("/"):
log_url += "/"
log_url += ("api/v1/jobs/%s/tasks/%s/attempts/%s/"
"logs/%s/logfile" %
(job.id, task.id, last_log_assoc.attempt,
log.identifier))
failed_logs.append(log)
failed_log_urls.append(log_url)

notified_users_query = JobNotifiedUser.query.filter_by(job=job)
if successful:
Expand Down Expand Up @@ -770,7 +771,7 @@ def send_job_completion_mail(job_id, successful=True):
subject_template = DEFAULT_FAIL_SUBJECT

message = MIMEText(
body_template.render(job=job, failed_logs=failed_logs))
body_template.render(job=job, failed_log_urls=failed_log_urls))
message["Subject"] = subject_template.render(job=job)
message["From"] = FROM_ADDRESS

Expand Down

0 comments on commit 0f2bab2

Please sign in to comment.