equal
deleted
inserted
replaced
|
1 """ |
|
2 Daily cleanup job. |
|
3 |
|
4 Can be run as a cronjob to clean out old data from the database (only expired |
|
5 sessions at the moment). |
|
6 """ |
|
7 |
|
8 from django_extensions.management.jobs import DailyJob |
|
9 |
|
10 class Job(DailyJob): |
|
11 help = "Cache (db) cleanup Job" |
|
12 |
|
13 def execute(self): |
|
14 from django.conf import settings |
|
15 import os |
|
16 |
|
17 if settings.CACHE_BACKEND.startswith('db://'): |
|
18 os.environ['TZ'] = settings.TIME_ZONE |
|
19 table_name = settings.CACHE_BACKEND[5:] |
|
20 cursor = connection.cursor() |
|
21 cursor.execute("DELETE FROM %s WHERE %s < UTC_TIMESTAMP()" % \ |
|
22 (backend.quote_name(table_name), backend.quote_name('expires'))) |
|
23 transaction.commit_unless_managed() |