99import logging
1010import os
1111import re
12+ import shutil
1213import sys
1314
1415import pytz
@@ -45,33 +46,41 @@ def send_data(config):
4546
4647 return error_raised
4748
48- def write_enterprise_ids_to_file (eligible_enterprise_customer_uuids ):
49+ def create_enterprise_uuid_files (eligible_enterprise_customer_uuids ):
4950 """
50- Write eligible enterprise customer UUIDs to a file.
51+ Create a file for each eligible enterprise customer UUID.
52+
53+ File format: {enterprise_customer_uuid}.txt
5154
5255 Args:
5356 eligible_enterprise_customer_uuids (set): A set of eligible enterprise customer UUIDs.
5457 """
55- jenkins_workspace = os .environ .get ('WORKSPACE' )
56- if jenkins_workspace :
57- file_name = os .path .join (jenkins_workspace , 'report_eligible_enterprise_uuids.txt' )
58- try :
59- os .remove (file_name )
60- except FileNotFoundError :
61- pass
62- except Exception as e :
63- LOGGER .error (f"An error occurred while deleting the file: { e } " )
64- sys .exit (1 )
65- try :
66- with open (file_name , "w" ) as f :
67- f .write (" " .join (eligible_enterprise_customer_uuids ))
68- except Exception as e :
69- LOGGER .error (f"An error occurred while writing to the file: { e } " )
70- sys .exit (1 )
71- else :
72- LOGGER .error ("WORKSPACE environment variable is not set. Skipping writing eligible enterprise IDs to file." )
58+ jenkins_workspace = os .environ .get ('WORKSPACE' , '' )
59+
60+ if not os .path .isdir (jenkins_workspace ):
61+ LOGGER .error (
62+ "WORKSPACE env variable is not set or invalid. Skipping writing enterprise UUID files. WORKSPACE: [%s]" ,
63+ jenkins_workspace
64+ )
7365 sys .exit (1 )
7466
67+ # Path to enterprises directory
68+ enterprises_dir = os .path .join (jenkins_workspace , "enterprises" )
69+
70+ # If enterprises dir exists, remove it first
71+ if os .path .exists (enterprises_dir ):
72+ shutil .rmtree (enterprises_dir )
73+
74+ # Create a fresh enterprises dir
75+ os .makedirs (enterprises_dir )
76+
77+ for enterprise_customer_uuid in eligible_enterprise_customer_uuids :
78+ file_path = os .path .join (enterprises_dir , f"{ enterprise_customer_uuid } .txt" )
79+ with open (file_path , "w" ) as f :
80+ f .write (f"{ enterprise_customer_uuid } \n " )
81+
82+ LOGGER .info ("Created enterprise UUID file for: [%s]" , enterprise_customer_uuid )
83+
7584def cleanup_files (enterprise_id ):
7685 """
7786 Clean up any files created by sending the enterprise report.
@@ -135,7 +144,7 @@ def process_reports():
135144 sys .exit (1 )
136145
137146 # We are defining the current est time globally because we want the current time for a job
138- # to remain same thoughout the job. This ensures that a single report is not processed multiple times.
147+ # to remain same thoughout the job. This ensures that a single report is not processed multiple times.
139148 # See this comment for more details: https://2u-internal.atlassian.net/browse/ENT-9954?focusedCommentId=5356815
140149 est_timezone = pytz .timezone ('US/Eastern' )
141150 current_est_time = datetime .datetime .now (est_timezone )
@@ -158,7 +167,7 @@ def process_reports():
158167 else :
159168 LOGGER .info ('Not ready -- skipping this report.' )
160169 if args .run_mode == 'master' :
161- write_enterprise_ids_to_file (eligible_enterprise_customer_uuids )
170+ create_enterprise_uuid_files (eligible_enterprise_customer_uuids )
162171
163172 if error_raised :
164173 LOGGER .error (
0 commit comments