Skip to content

Commit

Permalink
Add cron job to remove old django sessions (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Oct 31, 2023
1 parent b023198 commit 41f07dd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# How to

Run `sh add_cronjob.sh` to add the `remove_old_django_session.sh` to crontab.

If you get a message 'no crontab for [user]' make sure you have a crontab by running this command :
```
crontab -e
```
9 changes: 9 additions & 0 deletions cron/add_cronjob.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

crontab -l > remove_django_session_cronjob

echo "0 0 * * * sh ${PWD}/remove_old_django_session.sh" >> remove_django_session_cronjob

crontab remove_django_session_cronjob

rm remove_django_session_cronjob
9 changes: 9 additions & 0 deletions cron/remove_old_django_session.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

DOCKER_DB=$(docker ps --format '{{.Names}}' | grep qgis-feed_postgis | head -1)
DB_USER=postgres
DB_NAME=qgisfeed
INTERVAL=1

docker exec $DOCKER_DB su - $DB_USER -c "psql -d $DB_NAME -c \"DELETE FROM
DJANGO_SESSION WHERE expire_date < now() - interval '$INTERVAL days';\""

0 comments on commit 41f07dd

Please sign in to comment.