diff options
Diffstat (limited to 'matweb')
| -rw-r--r-- | matweb/file_removal_scheduler.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/matweb/file_removal_scheduler.py b/matweb/file_removal_scheduler.py index 59bb9ca..d0f0d4b 100644 --- a/matweb/file_removal_scheduler.py +++ b/matweb/file_removal_scheduler.py | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | """ | ||
| 2 | Check regularly if files have not been downloaded | ||
| 3 | and delete them if they're too old | ||
| 4 | """ | ||
| 5 | |||
| 1 | import glob | 6 | import glob |
| 2 | import time | 7 | import time |
| 3 | import sys | 8 | import sys |
| @@ -7,13 +12,23 @@ import random | |||
| 7 | from matweb import utils | 12 | from matweb import utils |
| 8 | 13 | ||
| 9 | 14 | ||
| 10 | def run_file_removal_job(upload_folder_path): | 15 | def run_file_removal_job(upload_folder_path: str): |
| 11 | if random.randint(0, 10) == 0: | 16 | """ |
| 17 | Check for removals at about every 10th request | ||
| 18 | :param upload_folder_path: path were the uploaded files are stored | ||
| 19 | :return: Void | ||
| 20 | """ | ||
| 21 | if random.randint(0, 10) == 0: # nosec | ||
| 12 | for file in glob.glob(upload_folder_path + '/*'): | 22 | for file in glob.glob(upload_folder_path + '/*'): |
| 13 | delete_file_when_too_old(file) | 23 | delete_file_when_too_old(file) |
| 14 | 24 | ||
| 15 | 25 | ||
| 16 | def delete_file_when_too_old(filepath): | 26 | def delete_file_when_too_old(filepath: str): |
| 27 | """ | ||
| 28 | Check if files are too old and remove em | ||
| 29 | :param filepath: Path of the file to check | ||
| 30 | :return: Void | ||
| 31 | """ | ||
| 17 | file_mod_time = os.stat(filepath).st_mtime | 32 | file_mod_time = os.stat(filepath).st_mtime |
| 18 | 33 | ||
| 19 | # time in second since last modification of file | 34 | # time in second since last modification of file |
