bug 628802, Migrate admin logs daily.

This commit is contained in:
Dave Dash 2011-02-01 15:48:42 -08:00
Родитель 1f5791231a
Коммит 5a05b2906a
4 изменённых файлов: 24 добавлений и 41 удалений

Просмотреть файл

@ -97,6 +97,15 @@ class ActivityLogMigrationTracker(object):
return self.redis.set(self.key, value)
#TODO(davedash): remove after admin is migrated
class AdminActivityLogMigrationTracker(ActivityLogMigrationTracker):
"""
Per bug 628802:
We will migrate activities from Remora admin.
"""
key = 'amo:activitylog:admin_migration'
def order_by_ids(qs, ids):
""" Please optimise me.
Going for the case that ids and qs is going to be small.

Просмотреть файл

@ -15,7 +15,8 @@ import redisutils
import amo
from amo.utils import chunked
from addons.utils import ActivityLogMigrationTracker
from addons.utils import AdminActivityLogMigrationTracker
from applications.models import Application, AppVersion
from bandwagon.models import Collection
from cake.models import Session
from devhub.models import ActivityLog, LegacyAddonLog
@ -102,56 +103,29 @@ def gc(test_result=True):
type=amo.COLLECTION_ANONYMOUS).delete()
@cronjobs.register
def migrate_logs():
def migrate_admin_logs():
# Get the highest id we've looked at.
a = ActivityLogMigrationTracker()
a = AdminActivityLogMigrationTracker()
id = a.get() or 0
items = LegacyAddonLog.objects.filter(pk__gt=id).values_list(
# filter here for addappversion
items = LegacyAddonLog.objects.filter(
type=amo.LOG.ADD_APPVERSION.id, pk__gt=id).values_list(
'id', flat=True)
for chunk in chunked(items, 100):
_migrate_logs.delay(chunk)
_migrate_admin_logs.delay(chunk)
a.set(chunk[-1])
@task
def _migrate_logs(items, **kw):
def _migrate_admin_logs(items, **kw):
print 'Processing: %d..%d' % (items[0], items[-1])
for item in LegacyAddonLog.objects.filter(pk__in=items):
kw = dict(user=item.user, created=item.created)
if item.type not in amo.LOG_KEEP:
continue
elif item.type in [amo.LOG.CREATE_ADDON.id, amo.LOG.SET_INACTIVE.id,
amo.LOG.UNSET_INACTIVE.id,
amo.LOG.SET_PUBLIC_STATS.id,
amo.LOG.UNSET_PUBLIC_STATS.id,
amo.LOG.ADD_RECOMMENDED.id,
amo.LOG.REMOVE_RECOMMENDED.id]:
amo.log(amo.LOG_BY_ID[item.type], item.addon, **kw)
elif item.type in [amo.LOG.ADD_USER_WITH_ROLE.id,
amo.LOG.REMOVE_USER_WITH_ROLE.id]:
amo.log(amo.LOG_BY_ID[item.type], item.addon,
(UserProfile, item.object1_id),
unicode(dict(amo.AUTHOR_CHOICES)[item.object2_id]), **kw)
elif item.type == amo.LOG.CHANGE_STATUS.id:
amo.log(amo.LOG_BY_ID[item.type], item.addon,
unicode(amo.STATUS_CHOICES[item.object1_id]), **kw)
# Items that require only a version
elif item.type in [amo.LOG.ADD_VERSION.id,
amo.LOG.APPROVE_VERSION.id,
amo.LOG.RETAIN_VERSION.id,
amo.LOG.ESCALATE_VERSION.id,
amo.LOG.REQUEST_VERSION.id]:
try:
v = Version.objects.get(pk=item.object1_id)
amo.log(amo.LOG_BY_ID[item.type], item.addon, v, **kw)
except Version.DoesNotExist:
print ('Version %d does not exist. No worries, it happens.'
% item.object1_id)
elif item.type == amo.LOG.DELETE_VERSION.id:
amo.log(amo.LOG_BY_ID[item.type], item.addon, item.name1, **kw)
amo.log(amo.LOG.ADD_APPVERSION, (Application, item.object1_id),
(AppVersion, item.object2_id), **kw)
@cronjobs.register

Просмотреть файл

@ -217,9 +217,8 @@ class REMOVE_RECOMMENDED:
class ADD_APPVERSION:
id = 35
# L10n: {0} is the application, {1.min/max} is the min/max version of the
# app
format = _(u'{addon} {version} now supports {0} {1.min}-{1.max}.')
# L10n: {0} is the application, {1} is the version of the app
format = _(u'{0} {1} added.')
class CHANGE_USER_WITH_ROLE:

Просмотреть файл

@ -96,6 +96,7 @@ HOME = /tmp
30 23 * * * $Z_CRON collection_meta
40 23 * * * $Z_CRON update_compat_info_for_fx4
45 23 * * * $DJANGO dump_apps
50 23 * * * $Z_CRON migrate_admin_logs
#Once per day after 2100 PST (after metrics is done)
35 21 * * * $Z_CRON update_addon_download_totals