Skip to content

Commit 095dbfb

Browse files
Merge branch 'rrfs-mpas-jedi' into update_RDASApp_UPP
2 parents 1395e8b + 4ba3d14 commit 095dbfb

4 files changed

Lines changed: 62 additions & 16 deletions

File tree

scripts/exrrfs_jedivar.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ${cpreq} "${FIXrrfs}"/jedi/obsop_name_map.yaml .
3737
${cpreq} "${FIXrrfs}"/jedi/keptvars.yaml .
3838
${cpreq} "${FIXrrfs}"/jedi/geovars.yaml .
3939
# if cold_start or not do_radar_ref, remove refl10cm and w from stream_list.atmosphere.analysis
40-
if [[ "${start_type}" == "cold" ]] || ! ${DO_RADAR_REF} ; then
40+
if [[ "${start_type}" == "cold" ]] || [[ ${DO_RADAR_REF} == "FALSE" ]]; then
4141
sed -i '$d;N;$d' stream_list/stream_list.atmosphere.analysis
4242
fi
4343
#

workflow/config_resources/config.base

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ fi
3434

3535
# DO_CLEAN
3636
if ${DO_CLEAN:-false} && ! ${REALTIME:-false}; then
37-
export STMP_RETENTION_CYCS=${STMP_RETENTION_CYCS:-24}
37+
export STMP_RETENTION_CYCS=${STMP_RETENTION_CYCS:-2}
3838
export COM_RETENTION_CYCS=${COM_RETENTION_CYCS:-2400} # 100 days
3939
export COM_LBC_RETENTION_CYCS=${COM_RETENTION_CYCS:-2400}
4040
export LOG_RETENTION_CYCS=${LOG_RETENTION_CYCS:-2400}
41-
export CLEAN_MODE=${CLEAN_MODE:-2} # default to 2 for retros
42-
# 1. only keep the latest few cycles; 2. purge current cycle stmp directories when it finishes successfully
41+
export CHECK_IS_CYC_DONE=${CHECK_IS_CYC_DONE:-true}
42+
export STMP_KEPT_TASKS=${STMP_KEPT_TASKS:-""} # eg. jedivar or jedivar,mpassit,upp
4343
fi
4444

4545
# ioda_airnow

workflow/rocoto_funcs/clean.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ def clean(xmlFile, expdir):
1313
clean_mode = int(os.getenv('CLEAN_MODE', '1'))
1414
dcTaskEnv = {
1515
'CLEAN_MODE': f'{clean_mode}',
16+
'CHECK_IS_CYC_DONE': os.getenv("CHECK_IS_CYC_DONE", "FALSE"), # default: TRUE for retros and FALSE for realtime
1617
'STMP_RETENTION_CYCS': os.getenv("STMP_RETENTION_CYCS", '6'),
1718
'COM_RETENTION_CYCS': os.getenv("COM_RETENTION_CYCS", '120'), # 120 hrs = 5 days
1819
'COM_LBC_RETENTION_CYCS': os.getenv("COM_LBC_RETENTION_CYCS", '48'), # 48 hrs = 2 days
1920
'LOG_RETENTION_CYCS': os.getenv("LOG_RETENTION_CYCS", '840'), # 840 hrs = 35 days
2021
# go back 'CLEAN_BACK_DAYS' from the first valid clean hour
2122
'CLEAN_BACK_DAYS': os.getenv("CLEAN_BACK_DAYS", '5'),
23+
'STMP_KEPT_TASKS': os.getenv("STMP_KEPT_TASKS", ''),
2224
}
2325

2426
# determine the dependency

workflow/sideload/clean.py

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44
import sys
55
import shutil
6-
from datetime import datetime, timedelta
6+
from datetime import datetime, timedelta, timezone
7+
import sqlite3
78
"""
89
clean up com/ stmp/ logs/ directoris mostly for realtime runs
910
but it can also be used for offline clean up at the command line
@@ -18,8 +19,41 @@ def is_directory_empty(directory_path):
1819
#
1920

2021

22+
def is_cycle_done(EXPDIR, CDATE):
23+
is_done = False
24+
db = f"{EXPDIR}/rrfs.db"
25+
conn = sqlite3.connect(db)
26+
cur = conn.cursor()
27+
cur.execute(f"SELECT * FROM cycles")
28+
rows = cur.fetchall() # id, cycle, activated, expired, done, draining
29+
for r in rows:
30+
dt = datetime.fromtimestamp(r[1], tz=timezone.utc)
31+
rcycle = dt.strftime("%Y%m%d%H%M")
32+
if rcycle == f'{CDATE}00':
33+
if r[4] != 0: # non-zero means "done"
34+
is_done = True
35+
break
36+
# ~~~~~~~~
37+
return is_done
38+
#
39+
# ----------------------------------------------------------------------
40+
#
41+
42+
2143
def day_clean(srcPath, cyc1, cyc2, srcType, WGF):
44+
check_is_cyc_done = os.getenv("CHECK_IS_CYC_DONE", "FALSE").upper() == "TRUE"
45+
if check_is_cyc_done: # mainly for retros. Not needed by realtime runs as we want to remove all old cycles including expired ones
46+
EXPDIR = os.getenv("EXPDIR", "EXPDIR_not_defined")
47+
STMP_KEPT_TASKS = os.getenv("STMP_KEPT_TASKS", "").strip()
48+
RUN = os.getenv("RUN", "")
49+
2250
for i in range(cyc1, cyc2 + 1):
51+
if check_is_cyc_done:
52+
CDATE = srcPath.rstrip("/")[-8:] + f'{i:02}'
53+
if not is_cycle_done(EXPDIR, CDATE): # skip the clean process for cycles not done yet
54+
print(f'{CDATE} NOT done yet, no cleaning')
55+
continue
56+
2357
if srcType == "log":
2458
pattern = f'{i:02}/{WGF}'
2559
elif srcType == "stmp":
@@ -28,20 +62,29 @@ def day_clean(srcPath, cyc1, cyc2, srcType, WGF):
2862
pattern = f'{i:02}/lbc/{WGF}'
2963
else: # com
3064
pattern = f'{i:02}/*/{WGF}'
65+
3166
pathlist = list(Path(srcPath).glob(pattern))
67+
if srcType == "stmp" and STMP_KEPT_TASKS != "": # exclude STMP_KEPT_TASKS from pathlist
68+
kept_tasks = STMP_KEPT_TASKS.split(",")
69+
excludes = []
70+
for task in kept_tasks:
71+
excludes.append(f'{RUN}_{task}_{i:02}_')
72+
pathlist = [p for p in pathlist if not any(ex in str(p) for ex in excludes)]
73+
3274
for mypath in pathlist:
33-
sys.stdout.write(f'purge {mypath}......')
34-
try:
35-
shutil.rmtree(mypath)
36-
sys.stdout.write(f'done!\n')
37-
except Exception as e:
38-
sys.stdout.write(f'\n An error occurred: {e}')
75+
if os.path.exists(mypath):
76+
sys.stdout.write(f'purge {mypath}......')
77+
try:
78+
shutil.rmtree(mypath)
79+
sys.stdout.write(f'done!\n')
80+
except Exception as e:
81+
sys.stdout.write(f'\n An error occurred: {e}')
3982
# ~~~~~~~~~~~~
4083
# remove empty directories
4184
#
4285
pathlist = list(Path(srcPath).glob(pattern.rstrip(f'/{WGF}')))
4386
for mypath in pathlist:
44-
if is_directory_empty(mypath):
87+
if os.path.exists(mypath) and is_directory_empty(mypath):
4588
os.rmdir(mypath)
4689
print(f'remove empty directory: {mypath}')
4790
# ~~~~~~~~~~~~
@@ -136,23 +179,24 @@ def group_clean(cdate, retention_cycs, srcBase, srcType, NET, RUN, WGF, rrfs_ver
136179
# remove data based on clean-realted environmental variables
137180
#
138181
cdate = datetime.strptime(f'{PDY}{cyc}', "%Y%m%d%H")
182+
cdate = cdate.replace(tzinfo=timezone.utc) # make it UTC-aware
139183
print(f'cdate={cdate}')
140184
print(f'stmp_retention_cycs={stmp_retention_cycs}')
141185
print(f'com_retention_cycs={com_retention_cycs}')
142186
print(f'com_lbc_retention_cycs={com_lbc_retention_cycs}')
143187
print(f'log_retention_cycs={log_retention_cycs}')
144188
print(f'clean_back_days={clean_back_days}')
145189

146-
print(f'\nclean stmp: {os.path.dirname(DATAROOT)}')
190+
print(f'\nTry to clean stmp: {os.path.dirname(DATAROOT)}')
147191
group_clean(cdate, stmp_retention_cycs, DATAROOT, 'stmp', NET, RUN, WGF, rrfs_ver)
148192

149-
print(f'\nclean com: {COMROOT}')
193+
print(f'\nTry to clean com: {COMROOT}')
150194
group_clean(cdate, com_retention_cycs, COMROOT, 'com', NET, RUN, WGF, rrfs_ver)
151195

152-
print(f'\nclean com_lbc: {COMROOT}')
196+
print(f'\nTry to clean com_lbc: {COMROOT}')
153197
group_clean(cdate, com_lbc_retention_cycs, COMROOT, 'com_lbc', NET, RUN, WGF, rrfs_ver)
154198

155-
print('\nclean log: ' + COMROOT.rstrip('/') + f'{NET}/{rrfs_ver}/logs')
199+
print('\nTry to clean log: ' + COMROOT.rstrip('/') + f'{NET}/{rrfs_ver}/logs')
156200
group_clean(cdate, log_retention_cycs, COMROOT, 'log', NET, RUN, WGF, rrfs_ver)
157201

158202
print('\nDone!')

0 commit comments

Comments
 (0)