44from sqlalchemy import select
55
66from testgen import settings
7+ from testgen .common .enums import JOB_STATUS_LABEL , JobStatus
78from testgen .common .models import get_current_session , with_database_session
89from testgen .common .models .hygiene_issue import HygieneIssue
910from testgen .common .models .notification_settings import (
@@ -23,7 +24,7 @@ class ProfilingRunEmailTemplate(BaseNotificationTemplate):
2324
2425 def get_subject_template (self ) -> str :
2526 return (
26- "[TestGen] Profiling Run {{format_status profiling_run.status }}: {{table_groups_name}}"
27+ "[TestGen] Profiling Run {{profiling_run.status_label }}: {{table_groups_name}}"
2728 "{{#if issue_count}}"
2829 ' | {{format_number issue_count}} hygiene {{pluralize issue_count "issue" "issues"}}'
2930 "{{/if}}"
@@ -32,9 +33,9 @@ def get_subject_template(self) -> str:
3233 def get_title_template (self ):
3334 return """
3435 TestGen Profiling Run - <span class="
35- {{#if (eq profiling_run.status 'Error ')}} text-red {{/if}}
36- {{#if (eq profiling_run.status 'Cancelled ')}} text-purple {{/if}}
37- ">{{format_status profiling_run.status }}</span>
36+ {{#if (eq profiling_run.status 'error ')}} text-red {{/if}}
37+ {{#if (eq profiling_run.status 'canceled ')}} text-purple {{/if}}
38+ ">{{profiling_run.status_label }}</span>
3839 """
3940
4041 def get_main_content_template (self ):
@@ -85,7 +86,7 @@ def get_main_content_template(self):
8586 </tr>
8687 <tr>
8788 <td class="summary__subtitle">
88- {{#if (eq profiling_run.status 'Complete ')}}
89+ {{#if (eq profiling_run.status 'completed ')}}
8990 {{#if (eq notification_trigger 'on_changes')}}
9091 Profiling run detected new hygiene issues.
9192 {{/if}}
@@ -95,15 +96,15 @@ def get_main_content_template(self):
9596 {{/if}}
9697 {{/if}}
9798 {{/if}}
98- {{#if (eq profiling_run.status 'Error ')}}
99+ {{#if (eq profiling_run.status 'error ')}}
99100 Profiling encountered an error.
100101 {{/if}}
101- {{#if (eq profiling_run.status 'Cancelled ')}}
102+ {{#if (eq profiling_run.status 'canceled ')}}
102103 Profiling run was canceled.
103104 {{/if}}
104105 </td>
105106 </tr>
106- {{#if (eq profiling_run.status 'Complete ')}}
107+ {{#if (eq profiling_run.status 'completed ')}}
107108 <tr>
108109 <td colspan="2" style="padding-top: 12px; padding-bottom: 12px;">
109110 <table cellspacing="0" cellpadding="0">
@@ -131,12 +132,12 @@ def get_main_content_template(self):
131132 </td>
132133 </tr>
133134 {{/if}}
134- {{#if (eq profiling_run.status 'Error ')}}
135+ {{#if (eq profiling_run.status 'error ')}}
135136 <tr>
136137 <td><div class="code">{{profiling_run.log_message}}</div></td>
137138 </tr>
138139 {{/if}}
139- {{#if (eq profiling_run.status 'Complete ')}}
140+ {{#if (eq profiling_run.status 'completed ')}}
140141 <tr>
141142 <td>
142143 <a class="link" href="{{profiling_run.issues_url}}" target="_blank">View {{format_number issue_count}} issues ></a>
@@ -241,6 +242,8 @@ def send_profiling_run_notifications(profiling_run: ProfilingRun, result_list_ct
241242 if not notifications :
242243 return
243244
245+ job_execution = profiling_run .job_execution
246+
244247 previous_run = profiling_run .get_previous ()
245248 issues = list (
246249 HygieneIssue .select_with_diff (
@@ -251,7 +254,7 @@ def send_profiling_run_notifications(profiling_run: ProfilingRun, result_list_ct
251254 )
252255
253256 triggers = {ProfilingRunNotificationTrigger .always }
254- if profiling_run .status in ("Error" , "Cancelled" ) or {None , True } & {is_new for _ , is_new in issues }:
257+ if job_execution .status in (JobStatus . ERROR , JobStatus . CANCELED ) or {None , True } & {is_new for _ , is_new in issues }:
255258 triggers .add (ProfilingRunNotificationTrigger .on_changes )
256259
257260 notifications = [ns for ns in notifications if ns .trigger in triggers ]
@@ -320,10 +323,11 @@ def send_profiling_run_notifications(profiling_run: ProfilingRun, result_list_ct
320323 "&source=email"
321324 )
322325 ),
323- "start_time" : profiling_run .profiling_starttime ,
324- "end_time" : profiling_run .profiling_endtime ,
325- "status" : profiling_run .status ,
326- "log_message" : profiling_run .log_message ,
326+ "start_time" : job_execution .started_at ,
327+ "end_time" : job_execution .completed_at ,
328+ "status" : job_execution .status ,
329+ "status_label" : JOB_STATUS_LABEL .get (job_execution .status , job_execution .status ),
330+ "log_message" : job_execution .error_message ,
327331 "table_ct" : profiling_run .table_ct ,
328332 "column_ct" : profiling_run .column_ct ,
329333 },
0 commit comments