@@ -134,10 +134,12 @@ def _clean_stale_state_files(
134
134
return handled
135
135
136
136
137
- def clean_mig_system_files (configuration , now = time . time () ):
137
+ def clean_mig_system_files (configuration , now = None ):
138
138
"""Inspect and clean up stale state files in mig_system_run.
139
139
Returns the number of actual actions taken for central throttle handling.
140
140
"""
141
+ if now is None :
142
+ now = time .time ()
141
143
return _clean_stale_state_files (
142
144
configuration ,
143
145
configuration .mig_system_files ,
@@ -147,10 +149,12 @@ def clean_mig_system_files(configuration, now=time.time()):
147
149
)
148
150
149
151
150
- def clean_sessid_to_mrls_link_home (configuration , now = time . time () ):
152
+ def clean_sessid_to_mrls_link_home (configuration , now = None ):
151
153
"""Inspect and clean up stale state files in sessid_to_mrsl_link_home.
152
154
Returns the number of actual actions taken for central throttle handling.
153
155
"""
156
+ if now is None :
157
+ now = time .time ()
154
158
return _clean_stale_state_files (
155
159
configuration ,
156
160
configuration .sessid_to_mrsl_link_home ,
@@ -160,10 +164,12 @@ def clean_sessid_to_mrls_link_home(configuration, now=time.time()):
160
164
)
161
165
162
166
163
- def clean_webserver_home (configuration , now = time . time () ):
167
+ def clean_webserver_home (configuration , now = None ):
164
168
"""Inspect and clean up stale state files in webserver_home.
165
169
Returns the number of actual actions taken for central throttle handling.
166
170
"""
171
+ if now is None :
172
+ now = time .time ()
167
173
return _clean_stale_state_files (
168
174
configuration ,
169
175
configuration .webserver_home ,
@@ -173,10 +179,12 @@ def clean_webserver_home(configuration, now=time.time()):
173
179
)
174
180
175
181
176
- def clean_no_job_helpers (configuration , now = time . time () ):
182
+ def clean_no_job_helpers (configuration , now = None ):
177
183
"""Inspect and clean up stale state empty job helpers inside user_home.
178
184
Returns the number of actual actions taken for central throttle handling.
179
185
"""
186
+ if now is None :
187
+ now = time .time ()
180
188
dummy_job_path = os .path .join (
181
189
configuration .user_home , "no_grid_jobs_in_grid_scheduler"
182
190
)
@@ -185,10 +193,12 @@ def clean_no_job_helpers(configuration, now=time.time()):
185
193
)
186
194
187
195
188
- def clean_twofactor_sessions (configuration , now = time . time () ):
196
+ def clean_twofactor_sessions (configuration , now = None ):
189
197
"""Inspect and clean up stale state files in twofactor_home.
190
198
Returns the number of actual actions taken for central throttle handling.
191
199
"""
200
+ if now is None :
201
+ now = time .time ()
192
202
return _clean_stale_state_files (
193
203
configuration ,
194
204
configuration .twofactor_home ,
@@ -198,11 +208,13 @@ def clean_twofactor_sessions(configuration, now=time.time()):
198
208
)
199
209
200
210
201
- def handle_state_cleanup (configuration , now = time . time () ):
211
+ def handle_state_cleanup (configuration , now = None ):
202
212
"""Inspect various state dirs to clean up general stale old temporay files.
203
213
Returns the number of actual actions taken for central throttle handling.
204
214
"""
205
215
_logger = configuration .logger
216
+ if now is None :
217
+ now = time .time ()
206
218
handled = 0
207
219
_logger .debug ("handle pending state cleanups" )
208
220
handled += clean_mig_system_files (configuration , now )
@@ -217,11 +229,13 @@ def handle_state_cleanup(configuration, now=time.time()):
217
229
return handled
218
230
219
231
220
- def handle_session_cleanup (configuration , now = time . time () ):
232
+ def handle_session_cleanup (configuration , now = None ):
221
233
"""Inspect various state dirs to clean up stale session files specifically.
222
234
Returns the number of actual actions taken for central throttle handling.
223
235
"""
224
236
_logger = configuration .logger
237
+ if now is None :
238
+ now = time .time ()
225
239
handled = 0
226
240
_logger .debug ("handle pending session cleanups" )
227
241
if configuration .site_enable_jobs :
@@ -353,7 +367,7 @@ def manage_single_req(configuration, req_id, req_path, db_path, now):
353
367
)
354
368
355
369
356
- def manage_trivial_user_requests (configuration , now = time . time () ):
370
+ def manage_trivial_user_requests (configuration , now = None ):
357
371
"""Inspect user_pending dir and take care of any request, which do not
358
372
require operator interaction. That is, accept or reject any password reset
359
373
requests depending on reset token validity, renew any with complete peer
@@ -364,6 +378,8 @@ def manage_trivial_user_requests(configuration, now=time.time()):
364
378
Returns the number of actual actions taken for central throttle handling.
365
379
"""
366
380
_logger = configuration .logger
381
+ if now is None :
382
+ now = time .time ()
367
383
handled = 0
368
384
now = time .time ()
369
385
db_path = default_db_path (configuration )
@@ -389,12 +405,14 @@ def manage_trivial_user_requests(configuration, now=time.time()):
389
405
return handled
390
406
391
407
392
- def remind_and_expire_user_pending (configuration , now = time . time () ):
408
+ def remind_and_expire_user_pending (configuration , now = None ):
393
409
"""Inspect user_pending dir and inform about pending but aging account
394
410
requests that need operator or user action.
395
411
Returns the number of actual actions taken for central throttle handling.
396
412
"""
397
413
_logger = configuration .logger
414
+ if now is None :
415
+ now = time .time ()
398
416
handled = 0
399
417
now = time .time ()
400
418
for filename in listdir (configuration .user_pending ):
@@ -446,11 +464,13 @@ def remind_and_expire_user_pending(configuration, now=time.time()):
446
464
return handled
447
465
448
466
449
- def handle_pending_requests (configuration , now = time . time () ):
467
+ def handle_pending_requests (configuration , now = None ):
450
468
"""Inspect various state dirs to remind or clean up stale requests.
451
469
Returns the number of actual actions taken for central throttle handling.
452
470
"""
453
471
_logger = configuration .logger
472
+ if now is None :
473
+ now = time .time ()
454
474
handled = 0
455
475
_logger .debug ("handle pending requests" )
456
476
handled += manage_trivial_user_requests (configuration , now )
@@ -463,12 +483,14 @@ def handle_pending_requests(configuration, now=time.time()):
463
483
return handled
464
484
465
485
466
- def handle_cache_updates (configuration , now = time . time () ):
486
+ def handle_cache_updates (configuration , now = None ):
467
487
"""Inspect internal cache update markers and handle any corresponding cache
468
488
updates in one place to avoid thrashing.
469
489
Returns the number of actual actions taken for central throttle handling.
470
490
"""
471
491
_logger = configuration .logger
492
+ if now is None :
493
+ now = time .time ()
472
494
handled = 0
473
495
_logger .debug ("handle pending cache updates" )
474
496
# TODO: actually handle vgrid/user/resource/... cache updates
@@ -479,13 +501,15 @@ def handle_cache_updates(configuration, now=time.time()):
479
501
return handled
480
502
481
503
482
- def handle_janitor_tasks (configuration , now = time . time () ):
504
+ def handle_janitor_tasks (configuration , now = None ):
483
505
"""A wrapper to take care of all regular janitor tasks like clean up and
484
506
cache updates.
485
507
Returns the number of actual tasks completed to let the main thread know if
486
508
it should throttle down or continue next run right away.
487
509
"""
488
510
_logger = configuration .logger
511
+ if now is None :
512
+ now = time .time ()
489
513
tasks_completed = 0
490
514
_logger .info ("handle any pending janitor tasks" )
491
515
if _lookup_last_run (configuration , "state-cleanup" ) + SECS_PER_DAY < now :
0 commit comments