From 31cc35a674fde3fff6967ababe7e9fd68353b2a3 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Wed, 15 May 2024 18:40:19 +0300 Subject: [PATCH] Add refresh-cache script and crontab sample Add script and crontab sample: - `scripts/refresh-cache`: can be run from a cron job to refresh the cache. - `scripts/refresh-cache.crontab`: sample user crontab for refreshing the cache daily. Signed-off-by: Nir Soffer --- test/README.md | 23 +++++++++++++++++++++++ test/scripts/refresh-cache | 22 ++++++++++++++++++++++ test/scripts/refresh-cache.crontab | 9 +++++++++ 3 files changed, 54 insertions(+) create mode 100755 test/scripts/refresh-cache create mode 100644 test/scripts/refresh-cache.crontab diff --git a/test/README.md b/test/README.md index 8965a6a492..8e56b0c024 100644 --- a/test/README.md +++ b/test/README.md @@ -175,6 +175,29 @@ drenv cleanup This should not be needed. +## Caching resources + +If you run the drenv tool with a flaky network you can improve +reliability of starting the environment by caching resources. + +To cache resources for the `regional-dr.yaml` environment run: + +``` +drenv cache envs/regional-dr.yaml +``` + +The cache expires in 2 days. To refresh the cache daily, you can install +a cron job to run `scripts/refresh-cache` daily as the user used to run +the environment. + +See the `scripts/refresh-cache.crontab` for example user crontab. + +To clear the cached resources run: + +``` +drenv clear +``` + ## The environment file To create an environment you need an yaml file describing the diff --git a/test/scripts/refresh-cache b/test/scripts/refresh-cache new file mode 100755 index 0000000000..dbf26cdfe0 --- /dev/null +++ b/test/scripts/refresh-cache @@ -0,0 +1,22 @@ +#!/bin/sh + +env_file=envs/regional-dr.yaml +attempts=10 +delay_seconds=60 + +test_dir="$(dirname $(dirname $0))" + +echo "$(date) Entering $test_dir" +cd "$test_dir" + +echo "$(date) Activating virtual environment" +source ../venv + +for i in $(seq 1 $attempts); do + echo "$(date) Refreshing drenv cache (attempt $i/$attempts)" + drenv cache -v "$env_file" && exit 0 + sleep $delay_seconds +done + +echo "Failed to refresh drenv cache" +exit 1 diff --git a/test/scripts/refresh-cache.crontab b/test/scripts/refresh-cache.crontab new file mode 100644 index 0000000000..f72b3519f1 --- /dev/null +++ b/test/scripts/refresh-cache.crontab @@ -0,0 +1,9 @@ +# To refresh the cache daily, edit the user crotab (crontab -e) and add the +# content bellow. +# NOTES: +# - update the path to the ramen directory. +# - ensure all the tools are in the specified PATH. + +PATH=/bin:/usr/bin:/usr/local/bin + +0 3 * * * /home/github/ramen/test/scripts/refresh-cache