Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #281 from CSCfi/CSCMETAX-418-fix-reference-data-up…
Browse files Browse the repository at this point in the history
…date-cron

CSCMETAX-418: [REF] Refactor old cron/update_reference_data.py to man…
  • Loading branch information
junsk1 authored Jun 8, 2018
2 parents 4fb374c + cbd0b60 commit 8c65abd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
2 changes: 0 additions & 2 deletions src/metax_api/cron/__init__.py

This file was deleted.

34 changes: 0 additions & 34 deletions src/metax_api/cron/update_reference_data.py

This file was deleted.

26 changes: 26 additions & 0 deletions src/metax_api/management/commands/updatereferencedata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import logging

from django.core.management.base import BaseCommand, CommandError

from metax_api.utils import RedisSentinelCache, ReferenceDataLoader


_logger = logging.getLogger(__name__)


class Command(BaseCommand):

help = 'Reload reference data to cache from ElasticSearch'

def handle(self, *args, **options):
self._update_reference_data()

def _update_reference_data(self):
_logger.info('Updating reference data...')
try:
cache = RedisSentinelCache(master_only=True)
ReferenceDataLoader.populate_cache_reference_data(cache)
except Exception as e:
_logger.exception('Reference data update ended in an error: %s' % str(e))
raise CommandError(e)
_logger.info('Reference data updated')

0 comments on commit 8c65abd

Please sign in to comment.