Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
bug 768136 - Add GC to Market
Browse files Browse the repository at this point in the history
built market specific gc handler "mkt_gc"
  • Loading branch information
jrconlin authored and cvan committed Jul 24, 2012
1 parent 21b09e3 commit a6b6db6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
19 changes: 18 additions & 1 deletion apps/market/cron.py
Expand Up @@ -8,8 +8,9 @@

from addons.models import Addon, AddonUser
import amo
from amo.utils import send_mail_jinja
from amo.utils import chunked, send_mail_jinja
from market.models import AddonPremium, Refund
from devhub.models import ActivityLog

log = commonware.log.getLogger('z.cron')

Expand Down Expand Up @@ -63,3 +64,19 @@ def mail_pending_refunds():
'market/emails/refund-nag.txt', ctx,
from_email=settings.NOBODY_EMAIL,
recipient_list=[owner])


@cronjobs.register
def mkt_gc(**kw):
"""Site-wide garbage collections."""

days_ago = lambda days: datetime.today() - timedelta(days=days)

log.debug('Collecting data to delete')
logs = (ActivityLog.objects.filter(created__lt=days_ago(90))
.exclude(action__in=amo.LOG_KEEP).values_list('id', flat=True))

for chunk in chunked(logs, 100):
chunk.sort()
log.debug('Deleting log entries: %s' % str(chunk))
amo.tasks.delete_logs.delay(chunk)
16 changes: 16 additions & 0 deletions apps/market/tests/test_cron.py
Expand Up @@ -8,6 +8,8 @@

import amo
import amo.tests
from devhub.models import ActivityLog
from market.cron import clean_out_addonpremium, mail_pending_refunds, mkt_gc
from addons.models import Addon, AddonUser
from market.cron import clean_out_addonpremium, mail_pending_refunds
from market.models import AddonPremium, Refund
Expand Down Expand Up @@ -118,3 +120,17 @@ def test_email_escaping(self):
assert '1 request' in email.body
assert 'not.this.domain.com' in email.body
eq_(email.to, [self.author.email])


class TestGarbage(amo.tests.TestCase):

def setUp(self):
self.user = UserProfile.objects.create(email='gc_test@example.com',
name='gc_test')
amo.log(amo.LOG.CUSTOM_TEXT, 'testing', user=self.user,
created=datetime(2001, 1, 1))

def test_garbage_collection(self):
eq_(ActivityLog.objects.all().count(), 1)
mkt_gc()
eq_(ActivityLog.objects.all().count(), 0)
1 change: 1 addition & 0 deletions scripts/crontab/crontab.tpl
Expand Up @@ -44,6 +44,7 @@ HOME=/tmp
30 1 * * * {{ z_cron }} update_user_ratings
40 1 * * * {{ z_cron }} update_weekly_downloads
50 1 * * * {{ z_cron }} gc
45 1 * * * {{ z_cron }} mkt_gc --settings=settings_local_mkt
30 2 * * * {{ z_cron }} mail_pending_refunds --settings=settings_local_mkt
45 2 * * * {{ django }} process_addons --task=update_manifests --settings=settings_local_mkt
30 3 * * * {{ django }} cleanup
Expand Down

0 comments on commit a6b6db6

Please sign in to comment.