Skip to content

Commit 6fda6bc

Browse files
committed
Address a couple of important PR322 review comments. Thanks @rasmunk
1 parent 0d756f1 commit 6fda6bc

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

mig/install/migrid-init.d-rh-template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ start_all() {
388388
return 0
389389
}
390390

391+
# TODO: should we use PID_FILE in all stop_X handlers like in deb version?
391392
stop_script() {
392393
check_enabled "jobs" || return
393394
DAEMON_PATH=${MIG_SCRIPT}

mig/lib/janitor.py

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ def _clean_stale_state_files(
134134
return handled
135135

136136

137-
def clean_mig_system_files(configuration, now=time.time()):
137+
def clean_mig_system_files(configuration, now=None):
138138
"""Inspect and clean up stale state files in mig_system_run.
139139
Returns the number of actual actions taken for central throttle handling.
140140
"""
141+
if now is None:
142+
now = time.time()
141143
return _clean_stale_state_files(
142144
configuration,
143145
configuration.mig_system_files,
@@ -147,10 +149,12 @@ def clean_mig_system_files(configuration, now=time.time()):
147149
)
148150

149151

150-
def clean_sessid_to_mrls_link_home(configuration, now=time.time()):
152+
def clean_sessid_to_mrls_link_home(configuration, now=None):
151153
"""Inspect and clean up stale state files in sessid_to_mrsl_link_home.
152154
Returns the number of actual actions taken for central throttle handling.
153155
"""
156+
if now is None:
157+
now = time.time()
154158
return _clean_stale_state_files(
155159
configuration,
156160
configuration.sessid_to_mrsl_link_home,
@@ -160,10 +164,12 @@ def clean_sessid_to_mrls_link_home(configuration, now=time.time()):
160164
)
161165

162166

163-
def clean_webserver_home(configuration, now=time.time()):
167+
def clean_webserver_home(configuration, now=None):
164168
"""Inspect and clean up stale state files in webserver_home.
165169
Returns the number of actual actions taken for central throttle handling.
166170
"""
171+
if now is None:
172+
now = time.time()
167173
return _clean_stale_state_files(
168174
configuration,
169175
configuration.webserver_home,
@@ -173,10 +179,12 @@ def clean_webserver_home(configuration, now=time.time()):
173179
)
174180

175181

176-
def clean_no_job_helpers(configuration, now=time.time()):
182+
def clean_no_job_helpers(configuration, now=None):
177183
"""Inspect and clean up stale state empty job helpers inside user_home.
178184
Returns the number of actual actions taken for central throttle handling.
179185
"""
186+
if now is None:
187+
now = time.time()
180188
dummy_job_path = os.path.join(
181189
configuration.user_home, "no_grid_jobs_in_grid_scheduler"
182190
)
@@ -185,10 +193,12 @@ def clean_no_job_helpers(configuration, now=time.time()):
185193
)
186194

187195

188-
def clean_twofactor_sessions(configuration, now=time.time()):
196+
def clean_twofactor_sessions(configuration, now=None):
189197
"""Inspect and clean up stale state files in twofactor_home.
190198
Returns the number of actual actions taken for central throttle handling.
191199
"""
200+
if now is None:
201+
now = time.time()
192202
return _clean_stale_state_files(
193203
configuration,
194204
configuration.twofactor_home,
@@ -198,11 +208,13 @@ def clean_twofactor_sessions(configuration, now=time.time()):
198208
)
199209

200210

201-
def handle_state_cleanup(configuration, now=time.time()):
211+
def handle_state_cleanup(configuration, now=None):
202212
"""Inspect various state dirs to clean up general stale old temporay files.
203213
Returns the number of actual actions taken for central throttle handling.
204214
"""
205215
_logger = configuration.logger
216+
if now is None:
217+
now = time.time()
206218
handled = 0
207219
_logger.debug("handle pending state cleanups")
208220
handled += clean_mig_system_files(configuration, now)
@@ -217,11 +229,13 @@ def handle_state_cleanup(configuration, now=time.time()):
217229
return handled
218230

219231

220-
def handle_session_cleanup(configuration, now=time.time()):
232+
def handle_session_cleanup(configuration, now=None):
221233
"""Inspect various state dirs to clean up stale session files specifically.
222234
Returns the number of actual actions taken for central throttle handling.
223235
"""
224236
_logger = configuration.logger
237+
if now is None:
238+
now = time.time()
225239
handled = 0
226240
_logger.debug("handle pending session cleanups")
227241
if configuration.site_enable_jobs:
@@ -353,7 +367,7 @@ def manage_single_req(configuration, req_id, req_path, db_path, now):
353367
)
354368

355369

356-
def manage_trivial_user_requests(configuration, now=time.time()):
370+
def manage_trivial_user_requests(configuration, now=None):
357371
"""Inspect user_pending dir and take care of any request, which do not
358372
require operator interaction. That is, accept or reject any password reset
359373
requests depending on reset token validity, renew any with complete peer
@@ -364,6 +378,8 @@ def manage_trivial_user_requests(configuration, now=time.time()):
364378
Returns the number of actual actions taken for central throttle handling.
365379
"""
366380
_logger = configuration.logger
381+
if now is None:
382+
now = time.time()
367383
handled = 0
368384
now = time.time()
369385
db_path = default_db_path(configuration)
@@ -389,12 +405,14 @@ def manage_trivial_user_requests(configuration, now=time.time()):
389405
return handled
390406

391407

392-
def remind_and_expire_user_pending(configuration, now=time.time()):
408+
def remind_and_expire_user_pending(configuration, now=None):
393409
"""Inspect user_pending dir and inform about pending but aging account
394410
requests that need operator or user action.
395411
Returns the number of actual actions taken for central throttle handling.
396412
"""
397413
_logger = configuration.logger
414+
if now is None:
415+
now = time.time()
398416
handled = 0
399417
now = time.time()
400418
for filename in listdir(configuration.user_pending):
@@ -446,11 +464,13 @@ def remind_and_expire_user_pending(configuration, now=time.time()):
446464
return handled
447465

448466

449-
def handle_pending_requests(configuration, now=time.time()):
467+
def handle_pending_requests(configuration, now=None):
450468
"""Inspect various state dirs to remind or clean up stale requests.
451469
Returns the number of actual actions taken for central throttle handling.
452470
"""
453471
_logger = configuration.logger
472+
if now is None:
473+
now = time.time()
454474
handled = 0
455475
_logger.debug("handle pending requests")
456476
handled += manage_trivial_user_requests(configuration, now)
@@ -463,12 +483,14 @@ def handle_pending_requests(configuration, now=time.time()):
463483
return handled
464484

465485

466-
def handle_cache_updates(configuration, now=time.time()):
486+
def handle_cache_updates(configuration, now=None):
467487
"""Inspect internal cache update markers and handle any corresponding cache
468488
updates in one place to avoid thrashing.
469489
Returns the number of actual actions taken for central throttle handling.
470490
"""
471491
_logger = configuration.logger
492+
if now is None:
493+
now = time.time()
472494
handled = 0
473495
_logger.debug("handle pending cache updates")
474496
# TODO: actually handle vgrid/user/resource/... cache updates
@@ -479,13 +501,15 @@ def handle_cache_updates(configuration, now=time.time()):
479501
return handled
480502

481503

482-
def handle_janitor_tasks(configuration, now=time.time()):
504+
def handle_janitor_tasks(configuration, now=None):
483505
"""A wrapper to take care of all regular janitor tasks like clean up and
484506
cache updates.
485507
Returns the number of actual tasks completed to let the main thread know if
486508
it should throttle down or continue next run right away.
487509
"""
488510
_logger = configuration.logger
511+
if now is None:
512+
now = time.time()
489513
tasks_completed = 0
490514
_logger.info("handle any pending janitor tasks")
491515
if _lookup_last_run(configuration, "state-cleanup") + SECS_PER_DAY < now:

tests/fixture/confs-stdlocal/migrid-init.d-rh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ start_all() {
388388
return 0
389389
}
390390

391+
# TODO: should we use PID_FILE in all stop_X handlers like in deb version?
391392
stop_script() {
392393
check_enabled "jobs" || return
393394
DAEMON_PATH=${MIG_SCRIPT}

0 commit comments

Comments
 (0)