Skip to content

Commit

Permalink
Bring back script run status (#1067)
Browse files Browse the repository at this point in the history
Co-authored-by: Jayasimha Raghavan <87547684+jayasimha-raghavan-unskript@users.noreply.github.com>
  • Loading branch information
1 parent 495bfcf commit be0d00e
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions unskript-ctl/unskript_ctl_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ def create_temp_files_of_failed_check_results(self,
return list_of_failed_files

def create_script_summary_message(self, output_metadata_file: str):
# message = ''
message = ''
if os.path.exists(output_metadata_file) is False:
self.logger.error(f"ERROR: The metadata file is missing, please check if file exists? {output_metadata_file}")
return ''
return message

metadata = ''
with open(output_metadata_file, 'r', encoding='utf-8') as f:
Expand All @@ -215,24 +215,24 @@ def create_script_summary_message(self, output_metadata_file: str):
self.logger.debug(f"\tStatus: {metadata.get('status')} \n\tTime (in seconds): {metadata.get('time_taken')} \n\tError: {metadata.get('error')} \n")

# Remove from email
# message += f'''
# <br>
# <h3> Custom Script Run Result </h3>
# <table border="1">
# <tr>
# <th> Status </th>
# <th> Time (in seconds) </th>
# <th> Error </th>
# </tr>
# <tr>
# <td>{metadata.get('status')}</td>
# <td>{metadata.get('time_taken')}</td>
# <td>{metadata.get('error')}</td>
# </tr>
# </table>
# '''

return ''
message += f'''
<br>
<h3> Custom Script Run Result </h3>
<table border="1">
<tr>
<th> Status </th>
<th> Time (in seconds) </th>
<th> Error </th>
</tr>
<tr>
<td>{metadata.get('status')}</td>
<td>{metadata.get('time_taken')}</td>
<td>{metadata.get('error')}</td>
</tr>
</table>
'''

return message

def create_info_legos_output_file(self):
"""create_info_legos_output_file: This function creates a file that will
Expand Down Expand Up @@ -469,6 +469,10 @@ def prepare_combined_email(self,
if info_result:
message += info_result
self.create_info_legos_output_file()
# print("Output Metadata File\n",output_metadata_file)
if output_metadata_file:
message += self.create_script_summary_message(output_metadata_file=output_metadata_file)
temp_attachment = self.create_email_attachment(output_metadata_file=output_metadata_file)

if len(os.listdir(self.execution_dir)) == 0 or not self.create_tarball_archive(tar_file_name=tar_file_name, output_metadata_file=None, parent_folder=parent_folder):
self.logger.error("Execution directory is empty , tarball creation unsuccessful!")
Expand Down Expand Up @@ -560,6 +564,9 @@ def send_sendgrid_notification(self,
if len(os.listdir(self.execution_dir)) == 0 or not self.create_tarball_archive(tar_file_name=tar_file_name, output_metadata_file=None, parent_folder=parent_folder):
self.logger.error("Execution directory is empty , tarball creation unsuccessful!")

if output_metadata_file:
html_message += self.create_script_summary_message(output_metadata_file=output_metadata_file)

info_result = self.create_info_gathering_action_result()
if info_result:
html_message += info_result
Expand Down

0 comments on commit be0d00e

Please sign in to comment.