setting up caching and bumping django version

pull/3/head
lance 5 years ago
parent 668650909f
commit 3572fcaa29

@ -0,0 +1,17 @@
from logging import getLogger
from huey import crontab
from huey.contrib.djhuey import periodic_task
from django.core.cache import cache
from django.conf import settings
from core.monero import AuctionDaemon, AuctionWallet
logger = getLogger('django.server')
@periodic_task(crontab(minute='*'))
def retrieve_daemon_stats():
logger.info('[INFO] Retrieving daemon statistics')
ad = AuctionDaemon()
if ad.connected:
daemon_info = ad.daemon.info()
cache.set('daemon_info', daemon_info, settings.CACHE_TTL)

@ -1,18 +1,20 @@
from django.shortcuts import render, HttpResponseRedirect, reverse from django.shortcuts import render, HttpResponseRedirect, reverse
from django.http import JsonResponse from django.http import JsonResponse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib import messages from django.contrib import messages
from django.core.cache import cache
from core.forms import UserShippingAddressForm from core.forms import UserShippingAddressForm
from core.models import UserShippingAddress from core.models import UserShippingAddress
from core.monero import AuctionDaemon, AuctionWallet from core.monero import AuctionDaemon, AuctionWallet
def home(request): def home(request):
daemon = AuctionDaemon() daemon_info = cache.get('daemon_info', None)
if daemon.connected: if daemon_info is None:
daemon_info = daemon.daemon.info() d = AuctionDaemon()
if d.connected:
daemon_info = AuctionDaemon().daemon.info()
else: else:
daemon_info = False daemon_info = False

@ -1,4 +1,4 @@
Django==2.2.8 Django>=2.2.9
Pillow==6.2.1 Pillow==6.2.1
boto3==1.10.45 boto3==1.10.45
coverage==5.0.3 coverage==5.0.3

@ -102,6 +102,7 @@ DATABASES = {
CACHE_HOST = os.environ.get('CACHE_HOST', 'localhost') CACHE_HOST = os.environ.get('CACHE_HOST', 'localhost')
CACHE_PORT = os.environ.get('CACHE_PORT', 6379) CACHE_PORT = os.environ.get('CACHE_PORT', 6379)
CACHE_TTL = os.environ.get('CACHE_TTL', 3600)
CACHES = { CACHES = {
'default': { 'default': {