Clean up some logging and remove old settings. No going back now.

This commit is contained in:
Wil Clouser 2011-11-06 10:20:07 -08:00 коммит произвёл Davor Spasovski
Родитель e5cdbc74cf
Коммит cfd4675f13
11 изменённых файлов: 21 добавлений и 48 удалений

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

@ -1105,8 +1105,6 @@ def version_changed(sender, **kw):
dispatch_uid='addons.search.index') dispatch_uid='addons.search.index')
def update_search_index(sender, instance, **kw): def update_search_index(sender, instance, **kw):
from . import tasks from . import tasks
if settings.SKIP_SEARCH_INDEX:
return
if not kw.get('raw'): if not kw.get('raw'):
tasks.index_addons.delay([instance.id]) tasks.index_addons.delay([instance.id])
@ -1116,8 +1114,6 @@ def update_search_index(sender, instance, **kw):
dispatch_uid='addons.search.unindex') dispatch_uid='addons.search.unindex')
def delete_search_index(sender, instance, **kw): def delete_search_index(sender, instance, **kw):
from . import tasks from . import tasks
if settings.SKIP_SEARCH_INDEX:
return
if not kw.get('raw'): if not kw.get('raw'):
tasks.unindex_addons.delay([instance.id]) tasks.unindex_addons.delay([instance.id])

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

@ -92,8 +92,6 @@ def delete_preview_files(id, **kw):
@task @task
def index_addons(ids, **kw): def index_addons(ids, **kw):
if not settings.USE_ELASTIC:
return
es = elasticutils.get_es() es = elasticutils.get_es()
log.info('Indexing addons %s-%s. [%s]' % (ids[0], ids[-1], len(ids))) log.info('Indexing addons %s-%s. [%s]' % (ids[0], ids[-1], len(ids)))
qs = Addon.uncached.filter(id__in=ids) qs = Addon.uncached.filter(id__in=ids)
@ -141,8 +139,6 @@ def attach_tags(addons):
@task @task
def unindex_addons(ids, **kw): def unindex_addons(ids, **kw):
if not settings.USE_ELASTIC:
return
for addon in ids: for addon in ids:
log.info('Removing addon [%s] from search index.' % addon) log.info('Removing addon [%s] from search index.' % addon)
Addon.unindex(addon) Addon.unindex(addon)

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

@ -88,15 +88,13 @@ def libraries():
def elastic(): def elastic():
elastic_results = None elastic_results = None
status = True status = False
if settings.USE_ELASTIC: try:
status = False health = elasticutils.get_es().cluster_health()
try: status = health['status'] != 'red'
health = elasticutils.get_es().cluster_health() elastic_results = health
status = health['status'] != 'red' except Exception:
elastic_results = health elastic_results = traceback.format_exc()
except Exception:
elastic_results = traceback.format_exc()
return status, elastic_results return status, elastic_results

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

@ -103,7 +103,6 @@
</ul> </ul>
</div> </div>
{% if settings.USE_ELASTIC %}
<div class="notification-box {{ status(status_summary.elastic) }}"> <div class="notification-box {{ status(status_summary.elastic) }}">
<h2>[Elastic Search] Health Check ({{ elastic_timer }}ms)</h2> <h2>[Elastic Search] Health Check ({{ elastic_timer }}ms)</h2>
<ul> <ul>
@ -118,6 +117,5 @@
{% endif %} {% endif %}
</ul> </ul>
</div> </div>
{% endif %}
{% endblock main_content %} {% endblock main_content %}

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

@ -306,7 +306,6 @@ class ESTestCase(TestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.es = elasticutils.get_es() cls.es = elasticutils.get_es()
settings.USE_ELASTIC = True
if ESTestCase.use_es is None: if ESTestCase.use_es is None:
for key, index in settings.ES_INDEXES.items(): for key, index in settings.ES_INDEXES.items():
@ -337,7 +336,6 @@ class ESTestCase(TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
settings.USE_ELASTIC = False
# Delete everything in reverse-order of the foriegn key dependencies. # Delete everything in reverse-order of the foriegn key dependencies.
models = (Platform, File, ApplicationsVersions, Version, models = (Platform, File, ApplicationsVersions, Version,
Translation, Addon, AppVersion, Application) Translation, Addon, AppVersion, Application)

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

@ -108,10 +108,8 @@ def cron_collection_meta(*addons, **kw):
@task @task
def index_collections(ids, **kw): def index_collections(ids, **kw):
if not settings.USE_ELASTIC:
return
es = elasticutils.get_es() es = elasticutils.get_es()
log.info('Indexing collections %s-%s [%s].' % (ids[0], ids[-1], len(ids))) log.debug('Indexing collections %s-%s [%s].' % (ids[0], ids[-1], len(ids)))
for c in Collection.objects.filter(id__in=ids): for c in Collection.objects.filter(id__in=ids):
Collection.index(search.extract(c), bulk=True, id=c.id) Collection.index(search.extract(c), bulk=True, id=c.id)
es.flush_bulk(forced=True) es.flush_bulk(forced=True)
@ -119,8 +117,6 @@ def index_collections(ids, **kw):
@task @task
def unindex_collections(ids, **kw): def unindex_collections(ids, **kw):
if not settings.USE_ELASTIC:
return
for id in ids: for id in ids:
log.info('Removing collection [%s] from search index.' % id) log.debug('Removing collection [%s] from search index.' % id)
Collection.unindex(id) Collection.unindex(id)

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

@ -23,7 +23,7 @@ def cleanup_extracted_file():
full = os.path.join(root, path) full = os.path.join(root, path)
age = time.time() - os.stat(full)[stat.ST_ATIME] age = time.time() - os.stat(full)[stat.ST_ATIME]
if (age) > (60 * 60): if (age) > (60 * 60):
log.info('Removing extracted files: %s, %dsecs old.' % (full, age)) log.debug('Removing extracted files: %s, %dsecs old.' % (full, age))
shutil.rmtree(full) shutil.rmtree(full)
# Nuke out the file and diff caches when the file gets removed. # Nuke out the file and diff caches when the file gets removed.
id = os.path.basename(path) id = os.path.basename(path)
@ -36,7 +36,6 @@ def cleanup_extracted_file():
key.update(str(id)) key.update(str(id))
cache.delete('%s:memoize:%s:%s' % (settings.CACHE_PREFIX, cache.delete('%s:memoize:%s:%s' % (settings.CACHE_PREFIX,
'file-viewer', key.hexdigest())) 'file-viewer', key.hexdigest()))
log.info('Removing cache file-viewer cache entries for: %s' % id)
@cronjobs.register @cronjobs.register

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

@ -408,18 +408,18 @@ class File(amo.models.OnChangeMixin, amo.models.ModelBase):
with amo.utils.guard('marketplace.watermark.%s' % dest) as locked: with amo.utils.guard('marketplace.watermark.%s' % dest) as locked:
if locked: if locked:
# The calling method will need to do something about this. # The calling method will need to do something about this.
log.error('Watermarking in progress of: %s for %s' % log.error('Watermarking collision: %s for %s' %
(self.pk, user.pk)) (self.pk, user.pk))
return return
if os.path.exists(dest): if os.path.exists(dest):
age = time.time() - os.stat(dest)[stat.ST_ATIME] age = time.time() - os.stat(dest)[stat.ST_ATIME]
if age > settings.WATERMARK_REUSE_SECONDS: if age > settings.WATERMARK_REUSE_SECONDS:
log.info('Removing stale watermark %s for %s %dsecs.' % log.debug('Removing stale watermark %s for %s %dsecs.' %
(self.pk, user.pk, age)) (self.pk, user.pk, age))
os.remove(dest) os.remove(dest)
else: else:
log.info('Already watermarked: %s for %s' % log.debug('Reusing existing watermarked file: %s for %s' %
(self.pk, user.pk)) (self.pk, user.pk))
# Touch the update time so that the cron job won't delete # Touch the update time so that the cron job won't delete
# us too quickly. # us too quickly.

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

@ -37,7 +37,7 @@ def extract_file(viewer, **kw):
msg.delete() msg.delete()
# This flag is so that we can signal when the extraction is completed. # This flag is so that we can signal when the extraction is completed.
flag = Message(viewer._extraction_cache_key()) flag = Message(viewer._extraction_cache_key())
task_log.info('[1@%s] Unzipping %s for file viewer.' % ( task_log.debug('[1@%s] Unzipping %s for file viewer.' % (
extract_file.rate_limit, viewer)) extract_file.rate_limit, viewer))
try: try:
@ -59,7 +59,7 @@ def migrate_jetpack_versions(ids, **kw):
# TODO(jbalogh): kill in bug 656997 # TODO(jbalogh): kill in bug 656997
for file_ in File.objects.filter(id__in=ids): for file_ in File.objects.filter(id__in=ids):
file_.jetpack_version = File.get_jetpack_version(file_.file_path) file_.jetpack_version = File.get_jetpack_version(file_.file_path)
task_log.info('Setting jetpack version to %s for File %s.' % task_log.debug('Setting jetpack version to %s for File %s.' %
(file_.jetpack_version, file_.id)) (file_.jetpack_version, file_.id))
file_.save() file_.save()

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

@ -17,7 +17,7 @@ task_log = commonware.log.getLogger('z.task')
@task @task
def delete_photo(dst, **kw): def delete_photo(dst, **kw):
task_log.info('[1@None] Deleting photo: %s.' % dst) task_log.debug('[1@None] Deleting photo: %s.' % dst)
if not dst.startswith(settings.USERPICS_PATH): if not dst.startswith(settings.USERPICS_PATH):
task_log.error("Someone tried deleting something they shouldn't: %s" task_log.error("Someone tried deleting something they shouldn't: %s"
@ -34,7 +34,7 @@ def delete_photo(dst, **kw):
@set_modified_on @set_modified_on
def resize_photo(src, dst, **kw): def resize_photo(src, dst, **kw):
"""Resizes userpics to 200x200""" """Resizes userpics to 200x200"""
task_log.info('[1@None] Resizing photo: %s' % dst) task_log.debug('[1@None] Resizing photo: %s' % dst)
try: try:
resize_image(src, dst, (200, 200)) resize_image(src, dst, (200, 200))
@ -45,10 +45,8 @@ def resize_photo(src, dst, **kw):
@task @task
def index_users(ids, **kw): def index_users(ids, **kw):
if not settings.USE_ELASTIC:
return
es = elasticutils.get_es() es = elasticutils.get_es()
task_log.info('Indexing users %s-%s [%s].' % (ids[0], ids[-1], len(ids))) task_log.debug('Indexing users %s-%s [%s].' % (ids[0], ids[-1], len(ids)))
for c in UserProfile.objects.filter(id__in=ids): for c in UserProfile.objects.filter(id__in=ids):
UserProfile.index(search.extract(c), bulk=True, id=c.id) UserProfile.index(search.extract(c), bulk=True, id=c.id)
es.flush_bulk(forced=True) es.flush_bulk(forced=True)
@ -56,10 +54,8 @@ def index_users(ids, **kw):
@task @task
def unindex_users(ids, **kw): def unindex_users(ids, **kw):
if not settings.USE_ELASTIC:
return
for id in ids: for id in ids:
task_log.info('Removing user [%s] from search index.' % id) task_log.debug('Removing user [%s] from search index.' % id)
UserProfile.unindex(id) UserProfile.unindex(id)

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

@ -37,9 +37,6 @@ DEBUG_PROPAGATE_EXCEPTIONS = True
# then connect to <yourhost>:8080 to view # then connect to <yourhost>:8080 to view
REMOTE_JS_DEBUG = False REMOTE_JS_DEBUG = False
# Skip indexing ES to speed things up?
SKIP_SEARCH_INDEX = False
# LESS CSS OPTIONS (Debug only) # LESS CSS OPTIONS (Debug only)
LESS_PREPROCESS = False # Compile LESS with Node, rather than client-side JS? LESS_PREPROCESS = False # Compile LESS with Node, rather than client-side JS?
LESS_LIVE_REFRESH = False # Refresh the CSS on save? LESS_LIVE_REFRESH = False # Refresh the CSS on save?
@ -1208,8 +1205,8 @@ ARECIBO_SETTINGS = {
# successfully logging in or out. # successfully logging in or out.
VALID_LOGIN_REDIRECTS = { VALID_LOGIN_REDIRECTS = {
'builder': 'https://builder.addons.mozilla.org', 'builder': 'https://builder.addons.mozilla.org',
'builderstage': 'https://builder-addons-next.allizom.org', 'builderstage': 'https://builder-addons.allizom.org',
'buildertrunk': 'https://builder-addons.allizom.org', 'buildertrunk': 'https://builder-addons-dev.allizom.org',
} }
# Secret key we send to builder so we can trust responses from the builder. # Secret key we send to builder so we can trust responses from the builder.
@ -1225,7 +1222,6 @@ ES_INDEXES = {'default': 'amo',
'update_counts': 'amo_stats', 'update_counts': 'amo_stats',
'download_counts': 'amo_stats'} 'download_counts': 'amo_stats'}
ES_TIMEOUT = 5 ES_TIMEOUT = 5
USE_ELASTIC = True
# Default AMO user id to use for tasks. # Default AMO user id to use for tasks.
TASK_USER_ID = 4757633 TASK_USER_ID = 4757633