Skip to content

Commit

Permalink
fixed error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
davidruvolo51 committed Mar 15, 2024
1 parent eb0c81b commit 6562e30
Showing 1 changed file with 46 additions and 39 deletions.
85 changes: 46 additions & 39 deletions rd3/molgenis_cleanup_index.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#///////////////////////////////////////////////////////////////////////////////
# FILE: molgenis_cleanup_index.py
# AUTHOR: David Ruvolo
# CREATED: 2024-01-11
# MODIFIED: 2024-01-11
# PURPOSE: clean up elastic search index table
# STATUS: stable
# PACKAGES: **see below**
# COMMENTS: NA
#///////////////////////////////////////////////////////////////////////////////
"""Clean up elastic search index
FILE: molgenis_cleanup_index.py
AUTHOR: David Ruvolo
CREATED: 2024-01-11
MODIFIED: 2024-01-11
PURPOSE: clean up elastic search index table
STATUS: stable
PACKAGES: **see below**
COMMENTS: NA
"""

from os import environ
from requests.exceptions import HTTPError
import molgenis.client as molgenis
from dotenv import load_dotenv
from os import environ
from tqdm import tqdm
load_dotenv()

Expand All @@ -21,50 +22,56 @@

# clear index action table
try:
response = rd3.delete(entity='sys_idx_IndexAction')
response.status_code == 204
except:
raise ValueError('Unable to delete table')
response = rd3.delete(entity='sys_idx_IndexAction')
if response.status_code != 204:
raise HTTPError(response.text)
print('Deleted table')
except HTTPError as error:
print(error)


#///////////////////////////////////////
# ///////////////////////////////////////

# clean index action group
try:
response = rd3.delete(entity='sys_idx_IndexActionGroup')
response.status_code == 204
except:
raise ValueError('Unable to delete table')
response = rd3.delete(entity='sys_idx_IndexActionGroup')
if response.status_code != 204:
raise HTTPError(response.text)
print('Deleted table')
except HTTPError as error:
print(error)

#///////////////////////////////////////
# ///////////////////////////////////////

# clear index job execution table
try:
response = rd3.delete(entity='sys_job_IndexJobExecution')
response.status_code == 204
except:
raise ValueError('Unable to delete table')
response = rd3.delete(entity='sys_job_IndexJobExecution')
if response.status_code != 204:
raise HTTPError(response.text)
print('Deleted table')
except HTTPError as error:
print(error)

# if the previous step fails, retrieve a list of IDs and delete them
# query='status=in=(FAILED,SUCCESS,PENDING)'
query='status=in=(FAILED,SUCCESS)'
# QUERY='status=in=(FAILED,SUCCESS,PENDING)'
QUERY = 'status=in=(FAILED,SUCCESS)'

job_index = rd3.get(
'sys_job_IndexJobExecution',
q=query,
attributes='identifier',
batch_size=10000
'sys_job_IndexJobExecution',
q=QUERY,
attributes='identifier',
batch_size=10000
)

if len(job_index):
print('Will attempt to delete', len(job_index), 'jobs')
job_index_ids = [row['identifier'] for row in job_index]
for batch in tqdm(range(0, len(job_index_ids), 1000)):
response = rd3.delete_list(
'sys_job_IndexJobExecution',
entities=job_index_ids[batch:batch+1000]
)
print('Will attempt to delete', len(job_index), 'jobs')
job_index_ids = [row['identifier'] for row in job_index]

for batch in tqdm(range(0, len(job_index_ids), 1000)):
response = rd3.delete_list(
'sys_job_IndexJobExecution',
entities=job_index_ids[batch:batch+1000]
)


rd3.logout()

0 comments on commit 6562e30

Please sign in to comment.