Skip to content

Commit

Permalink
ws_expirer: add option for running on storage targets only
Browse files Browse the repository at this point in the history
  • Loading branch information
staeglis committed Jan 9, 2025
1 parent 22ebfa5 commit 27c7015
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions sbin/ws_expirer
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ def processOpts():
default=False,
help="enable cleanup run (default is dry run)",
)
parser.add_option(
"-s",
"--space",
action="callback",
dest="single_space",
callback=vararg_callback,
default="",
help="pass a single space (inside a workspace) to clean up"
)
(options, args) = parser.parse_args()
if not options:
print("*** FATAL: No options defined. ***")
Expand Down Expand Up @@ -309,6 +318,13 @@ if not opts.fslist:
else:
fslist = opts.fslist

single_space = ""
try:
single_space = opts.single_space[0]
print(single_space)
except IndexError:
single_space = ""

if fslist == []:
print("Error: no workspace defined")
sys.exit(2)
Expand Down Expand Up @@ -361,7 +377,12 @@ for fs in fslist:
dbentriesws = get_dbentriesws(dbentries)
dbentryworkspaces = list(map(os.path.basename, dbentriesws))
workspacedelprefix = config["workspaces"][fs]["deleted"]
print("PHASE: checking for stray workspaces for", fs, dbdir, spaces)
if single_space != "":
spaces.remove(single_space)
print("PHASE: checking for stray workspaces for", fs, dbdir, single_space, ", ignoring ", spaces)
spaces = [single_space]
else:
print("PHASE: checking for stray workspaces for", fs, dbdir, spaces)
for space in spaces:
for ws in workspaces[space]: # (2) for for #87
if os.path.basename(ws) not in dbentryworkspaces:
Expand Down Expand Up @@ -446,7 +467,12 @@ for fs in fslist:
senderrormail("DB directory {0} does not contain .ws_db_magic, skipping to avoid data loss. Please check!".format(dbdir))
continue

print("PHASE: checking for workspaces to be expired for", fs, dbdir, spaces)
if single_space != "":
spaces.remove(single_space)
print("checking for workspaces to be expired for", fs, dbdir, single_space, ", ignoring ", spaces)
spaces = [single_space]
else:
print("PHASE: checking for workspaces to be expired for", fs, dbdir, spaces)
for dbentryfilename in glob.glob(os.path.join(dbdir, "*-*")):
reminder = 0
mailaddress = ""
Expand Down Expand Up @@ -484,6 +510,8 @@ for fs in fslist:
if workspace == "" or expiration == 0:
print(" FAILED to parse DB for", dbentryfilename)
continue
if single_space != "" and single_space not in workspace:
continue
if time.time() > expiration:
print(" expiring", dbentryfilename, " (expired", time.ctime(expiration), ")")
timestamp = str(int(time.time()))
Expand Down Expand Up @@ -578,7 +606,12 @@ for fs in fslist:
senderrormail("DB directory {0} does not contain .ws_db_magic, skipping to avoid data loss. Please check!".format(dbdir))
continue

print("PHASE: checking for expired workspaces for", fs, dbdir, spaces)
if single_space != "":
spaces.remove(single_space)
print("PHASE: checking for expired workspaces for", fs, dbdir, single_space, ", ignoring ", spaces)
spaces = [single_space]
else:
print("PHASE: checking for expired workspaces for", fs, dbdir, spaces)
dbdeldir = os.path.join(config["workspaces"][fs]["database"], config["workspaces"][fs]["deleted"])
keeptime = config["workspaces"][fs]["keeptime"]
print(" keeptime:", keeptime)
Expand All @@ -600,6 +633,8 @@ for fs in fslist:
if workspace == "" or expiration == 0:
print(" FAILED to parse DB for", dbentryfilename)
continue
if single_space != "" and single_space not in workspace:
continue
# take time of release from filename
released = dbentryfilename.split("-")[-1]
try:
Expand Down

0 comments on commit 27c7015

Please sign in to comment.