Commit 5f9e2ead authored by Christopher M Reffett's avatar Christopher M Reffett

Add manage.py cleanlinks command to remove expired links, add sample

cron script and notes on setup in README.md.
parent eeb2c0aa
......@@ -42,3 +42,11 @@ $ pip install -r requirements.txt
```
and you should be good to go.
### Cron
In order to expire links, you need to set up a cron job to run the manage.py
expirelinks command regularly. A sample cron script is available in the
repository and is named go-cleanlinks.cron. Drop this in cron.hourly and
change the paths so that they point to the virtualenv activate script and
manage.py.
#!/bin/sh
# Cron job to automatically expire outdated links, put this in cron.hourly
ACTIVATE_PATH=/path/to/virtualenv/activate
MANAGE_PATH=/path/to/go/manage.py
source ${ACTIVATE_PATH}
python ${MANAGE_PATH} expirelinks
from django.core.management.base import BaseCommand
from django.utils import timezone
from go.models import URL
class Command(BaseCommand):
help = 'Removes expired links from the database'
def handle(self, *args, **options):
for toexpire in URL.objects.filter(expires__lte=timezone.now()):
self.stdout.write("Removed URL %s (%s), expires %s" % (toexpire.target, toexpire.short, toexpire.expires))
toexpire.delete()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment