Skip to content

Commit

Permalink
Add refresh-cache script and crontab sample
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
nirs committed Jun 10, 2024
1 parent 6b40992 commit ebfee1e
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions test/scripts/refresh-cache
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions test/scripts/refresh-cache.crontab
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ebfee1e

Please sign in to comment.