84
84
def del_audit_entries_rerun (current_date ):
85
85
postgres_connection = PgresPool .getconn ()
86
86
postgres_cursor = postgres_connection .cursor ()
87
- del_sql = f"""
88
- DELETE FROM { mstr_schema } .{ audit_table } c
89
- where application_name='{ app_name } ' and batch_run_date='{ current_date } '
90
- """
91
- postgres_cursor .execute (del_sql )
92
- postgres_connection .commit ()
93
- postgres_cursor .close ()
94
- PgresPool .putconn (postgres_connection )
95
- return print (del_sql )
87
+ try :
88
+ del_sql = f"""
89
+ DELETE FROM { mstr_schema } .{ audit_table } c
90
+ where application_name='{ app_name } ' and batch_run_date='{ current_date } '
91
+ """
92
+ postgres_cursor .execute (del_sql )
93
+ postgres_connection .commit ()
94
+ postgres_cursor .close ()
95
+ PgresPool .putconn (postgres_connection )
96
+ print (del_sql )
97
+ return None
98
+ except Exception as e :
99
+ print (f"Failed to delete audit entries for application name { app_name } and date '{ current_date } ': { str (e )} " )
100
+ sys .exit (3 )
96
101
97
102
# Function to insert the audit batch status entry
98
103
def audit_batch_status_insert (table_name ,status ):
@@ -107,6 +112,7 @@ def audit_batch_status_insert(table_name,status):
107
112
return None
108
113
except Exception as e :
109
114
print (f"Error inserting record into to audit batch status table: { str (e )} " )
115
+ sys .exit (4 )
110
116
return None
111
117
finally :
112
118
# Return the connection to the pool
@@ -124,13 +130,19 @@ def get_active_tables(mstr_schema,app_name):
124
130
where active_ind = 'Y' and application_name='{ app_name } '
125
131
order by replication_order, source_table_name
126
132
"""
127
- with postgres_connection .cursor () as curs :
128
- curs .execute (list_sql )
129
- rows = curs .fetchall ()
130
- postgres_connection .commit ()
131
- postgres_cursor .close ()
132
- PgresPool .putconn (postgres_connection )
133
- return rows
133
+ try :
134
+ with postgres_connection .cursor () as curs :
135
+ curs .execute (list_sql )
136
+ rows = curs .fetchall ()
137
+ postgres_connection .commit ()
138
+ postgres_cursor .close ()
139
+ PgresPool .putconn (postgres_connection )
140
+ return rows
141
+ except Exception as e :
142
+ print (f"Error selecting record from cdc_master_table_list table: { str (e )} " )
143
+ sys .exit (5 )
144
+ return None
145
+
134
146
135
147
# In[9]: Function to extract data from Oracle
136
148
def extract_from_srcpg (table_name ,source_schema ,customsql_ind ,customsql_query ):
0 commit comments