Skip to content

Commit d04efa5

Browse files
committed
added the exit codes for pg2pg script
1 parent 4bcaf19 commit d04efa5

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

shared/ods_replication_pg2pg/data_replication_pg2pg.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,20 @@
8484
def del_audit_entries_rerun(current_date):
8585
postgres_connection = PgresPool.getconn()
8686
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)
96101

97102
# Function to insert the audit batch status entry
98103
def audit_batch_status_insert(table_name,status):
@@ -107,6 +112,7 @@ def audit_batch_status_insert(table_name,status):
107112
return None
108113
except Exception as e:
109114
print(f"Error inserting record into to audit batch status table: {str(e)}")
115+
sys.exit(4)
110116
return None
111117
finally:
112118
# Return the connection to the pool
@@ -124,13 +130,19 @@ def get_active_tables(mstr_schema,app_name):
124130
where active_ind = 'Y' and application_name='{app_name}'
125131
order by replication_order, source_table_name
126132
"""
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+
134146

135147
# In[9]: Function to extract data from Oracle
136148
def extract_from_srcpg(table_name,source_schema,customsql_ind,customsql_query):

0 commit comments

Comments
 (0)