Skip to content

Commit 34b2b7f

Browse files
authored
feat: remove deps.zip file after extracting the packages (#3)
Remove the deps.zip file to save storage inside the container. Store the time the packages were last fatched in the trigger file and read it from the trigger file instead of checking the creation date of the deps.zip file.
1 parent 02ad606 commit 34b2b7f

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [Improvement] Remove deps.zip file after extracting the packages. (by @mlabeeb03)
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import datetime
2-
import os
32
import time
43

54
from django.core.files.storage import storages
65

7-
DEPS_DIR = "/openedx/live-dependencies/deps"
86
DEPS_KEY = "deps.zip"
9-
DEPS_ZIP_PATH = DEPS_DIR[:-4] + DEPS_KEY
107
TRIGGER_FILE = "/openedx/live-dependencies/uwsgi_trigger"
118

129
# TODO Use a separate storage for live dependencies
@@ -15,16 +12,15 @@
1512
while True:
1613
if storage.exists(DEPS_KEY):
1714
remote_ts = storage.get_modified_time(DEPS_KEY)
15+
local_ts = None
16+
with open(TRIGGER_FILE, "r") as f:
17+
local_ts_str = f.read().strip()
18+
if local_ts_str:
19+
local_ts = datetime.datetime.fromisoformat(local_ts_str)
1820

19-
if os.path.exists(DEPS_ZIP_PATH):
20-
local_ts = os.path.getmtime(DEPS_ZIP_PATH)
21-
local_ts = datetime.datetime.fromtimestamp(
22-
local_ts, tz=datetime.timezone.utc
23-
)
24-
25-
if local_ts < remote_ts:
26-
with open(TRIGGER_FILE, "a"):
27-
os.utime(TRIGGER_FILE, None)
28-
# TODO What happens if download takes more than 10 seconds?
29-
# This could keep initiating a reload in a loop.
21+
if local_ts is None or local_ts < remote_ts:
22+
now = datetime.datetime.now(tz=datetime.timezone.utc)
23+
with open(TRIGGER_FILE, "w") as f:
24+
# Writing to the TRIGGER_FILE will cause uWSGI to reload the app
25+
f.write(now.isoformat())
3026
time.sleep(10)

tutorlivedeps/templates/livedeps/build/update_livedeps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121

2222
with zipfile.ZipFile(DEPS_ZIP_PATH, "r") as zip_ref:
2323
zip_ref.extractall(DEPS_DIR)
24+
25+
os.remove(DEPS_ZIP_PATH)

0 commit comments

Comments
 (0)