Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BAAN Data
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vamsikrishna.vemulamanda
BAAN Data
Commits
99830b0f
Commit
99830b0f
authored
Jul 06, 2021
by
vamsikrishna.vemulamanda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update delete_local_data
parent
42aa8e78
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
5 deletions
+37
-5
delete_local_data/delete_local_data
delete_local_data/delete_local_data
+37
-5
No files found.
delete_local_data/delete_local_data
View file @
99830b0f
import os
import shutil
from pathlib import Path
from sqlalchemy import create_engine
import logging
job_id = os.environ.get('JOB_ID', 'job_1')
directory = os.environ.get("LOCAL_PATH", 'ilens/prod/jubilant')
postgres_database = os.environ.get('postgres_database', default='ilens_jubilant')
postgre_user = os.environ.get('postgre_user', default='ilens')
postgre_password = os.environ.get('postgre_password', default='iLens#4321')
postgre_host = os.environ.get('postgre_host', default='postgres-db-service.ilens-infra.svc.cluster.local')
postgre_port = os.environ.get('postgre_port', default='5432')
job_id = os.environ.get('JOB_ID', 'job_6')
directory = os.environ.get("LOCAL_PATH", '/mnt/ilens/prod/jubilant')
directory = os.path.join(directory, job_id)
class DeleteLocalData:
def __init__(self):
try:
print("Connecting to postgres .......")
self.engine_data = 'postgresql+psycopg2://{}:{}@{}:{}/{}'.format(postgre_user, postgre_password,
postgre_host,
postgre_port, postgres_database)
self.engine = create_engine(self.engine_data)
except Exception as e:
print(e)
def delete_local_data(self):
try:
...
...
@@ -16,7 +32,7 @@ class DeleteLocalData:
dis = os.path.join(directory, filename)
if os.path.isfile(dis):
os.remove(dis)
logging.info
("Removed CSV files from base directory")
print
("Removed CSV files from base directory")
dis_list = []
for filename in os.listdir(directory):
...
...
@@ -30,8 +46,24 @@ class DeleteLocalData:
path_ = Path(dis)
if os.path.isdir(dis):
shutil.rmtree(dis)
logging.info("Removed all the subdirectories in Base directory")
print("Removed all the subdirectories in Base directory")
conn = self.engine.raw_connection()
cur = conn.cursor()
cur.execute("SELECT job_id, status from audit_data_table")
row = cur.fetchall()
data_name_list = []
data_status_list = []
curr_act = 'deleted'
for i in row:
data_name_list.append(i[0])
data_status_list.append(i[1])
data_updated_dict = dict(zip(data_name_list, data_status_list))
for key, value in data_updated_dict.items():
if value == 'Success':
cur.execute('''UPDATE audit_data_table SET current_activity = '{}' WHERE status = '{}';'''.format(curr_act, value))
conn.commit()
except Exception as e:
print(e)
logging.error(e)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment