setup some info logging

pull/1/head
lza_menace 4 years ago
parent f9153ee335
commit 803d427e8b

@ -1,6 +1,7 @@
from app.models import Operation from app.models import Operation
from app.library.digitalocean import do from app.library.digitalocean import do
from app.factory import db from app.factory import db
from flask import current_app
def to_ausd(amount): def to_ausd(amount):
@ -21,7 +22,7 @@ def cancel_operation(codename):
op.droplet_id = None op.droplet_id = None
op.volume_id = None op.volume_id = None
db.session.commit() db.session.commit()
print(f'Deleted droplet and associated volume for {codename}') current_app.logger.info(f'Deleted droplet and associated volume for {codename}')
if op.record_v4_id: if op.record_v4_id:
r = do.delete_record(op.record_v4_id) r = do.delete_record(op.record_v4_id)
if r: if r:
@ -33,6 +34,6 @@ def cancel_operation(codename):
if r: if r:
op.record_v6_id = None op.record_v6_id = None
db.session.commit() db.session.commit()
print(f'Deleted AAAA records for {codename}') current_app.logger.info(f'Deleted AAAA records for {codename}')
else: else:
print('Not an op') print('Not an op')

@ -3,6 +3,7 @@ from json import dumps as json_dumps
from datetime import timedelta from datetime import timedelta
from redis import Redis from redis import Redis
from requests import get as r_get from requests import get as r_get
from flask import current_app
from app.library.coingecko import get_market_data from app.library.coingecko import get_market_data
from app.library.monero import wallet from app.library.monero import wallet
from app.library.digitalocean import do from app.library.digitalocean import do
@ -14,6 +15,7 @@ class Cache(object):
self.redis = Redis(host=config.CACHE_HOST, port=config.CACHE_PORT) self.redis = Redis(host=config.CACHE_HOST, port=config.CACHE_PORT)
def store_data(self, item_name, expiration_minutes, data): def store_data(self, item_name, expiration_minutes, data):
current_app.logger.info(f'MISS - {item_name} - {expiration_minutes} minutes')
self.redis.setex( self.redis.setex(
item_name, item_name,
timedelta(minutes=expiration_minutes), timedelta(minutes=expiration_minutes),
@ -24,6 +26,7 @@ class Cache(object):
key_name = f'node_{codename}_info' key_name = f'node_{codename}_info'
data = self.redis.get(key_name) data = self.redis.get(key_name)
if data: if data:
current_app.logger.info(f'HIT - {key_name}')
return json_loads(data) return json_loads(data)
else: else:
try: try:
@ -40,6 +43,7 @@ class Cache(object):
key_name = f'wallet_txes_{account_idx}' key_name = f'wallet_txes_{account_idx}'
data = self.redis.get(key_name) data = self.redis.get(key_name)
if data: if data:
current_app.logger.info(f'HIT - {key_name}')
return json_loads(data) return json_loads(data)
else: else:
txes = wallet.get_transfers(account_idx) txes = wallet.get_transfers(account_idx)
@ -54,17 +58,21 @@ class Cache(object):
key_name = f'wallet_balances_{account_idx}{extra}' key_name = f'wallet_balances_{account_idx}{extra}'
data = self.redis.get(key_name) data = self.redis.get(key_name)
if data: if data:
current_app.logger.info(f'HIT - {key_name}')
return json_loads(data) return json_loads(data)
else: else:
balances = wallet.balances(account_idx, atomic) balances = wallet.balances(account_idx, atomic)
data = {'balance': balances[0], 'unlocked': balances[1]} data = {'balance': balances[0], 'unlocked': balances[1]}
self.store_data(key_name, 1, json_dumps(data)) self.store_data(key_name, 2, json_dumps(data))
return data return data
def show_droplet(self, droplet_id): def show_droplet(self, droplet_id):
if droplet_id is None:
return None
key_name = f'droplet_{droplet_id}' key_name = f'droplet_{droplet_id}'
data = self.redis.get(key_name) data = self.redis.get(key_name)
if data: if data:
current_app.logger.info(f'HIT - {key_name}')
return json_loads(data) return json_loads(data)
else: else:
droplet = do.show_droplet(droplet_id) droplet = do.show_droplet(droplet_id)
@ -75,6 +83,7 @@ class Cache(object):
key_name = f'volume_{volume_id}' key_name = f'volume_{volume_id}'
data = self.redis.get(key_name) data = self.redis.get(key_name)
if data: if data:
current_app.logger.info(f'HIT - {key_name}')
return json_loads(data) return json_loads(data)
else: else:
volume = do.show_volume(volume_id) volume = do.show_volume(volume_id)
@ -85,6 +94,7 @@ class Cache(object):
key_name = f'xmr_price_{cur}' key_name = f'xmr_price_{cur}'
data = self.redis.get(key_name) data = self.redis.get(key_name)
if data: if data:
current_app.logger.info(f'HIT - {key_name}')
return float(data.decode()) return float(data.decode())
else: else:
d = get_market_data() d = get_market_data()
@ -96,6 +106,7 @@ class Cache(object):
key_name = f'xmr_wallet_{subaddress_index}_txes' key_name = f'xmr_wallet_{subaddress_index}_txes'
data = self.redis.get(key_name) data = self.redis.get(key_name)
if data: if data:
current_app.logger.info(f'HIT - {key_name}')
return json_loads(data) return json_loads(data)
else: else:
wallet.get_transfers(subaddress_index) wallet.get_transfers(subaddress_index)

@ -1,4 +1,5 @@
from requests import get as r_get from requests import get as r_get
from flask import current_app
def get_market_data(coin_name='monero'): def get_market_data(coin_name='monero'):
@ -12,5 +13,6 @@ def get_market_data(coin_name='monero'):
} }
headers = {'accept': 'application/json'} headers = {'accept': 'application/json'}
url = f'https://api.coingecko.com/api/v3/coins/{coin_name}' url = f'https://api.coingecko.com/api/v3/coins/{coin_name}'
current_app.logger.info(f'Fetching {coin_name} price metrics from CoinGecko')
r = r_get(url, headers=headers, data=data) r = r_get(url, headers=headers, data=data)
return r.json() return r.json()

@ -1,4 +1,5 @@
import requests import requests
from flask import current_app
from app import config from app import config
@ -11,6 +12,7 @@ class DigitalOcean(object):
def make_req(self, method, endpoint, data=None): def make_req(self, method, endpoint, data=None):
url = self.base + endpoint url = self.base + endpoint
current_app.logger.info(f'{method.upper()} - {url}')
if method == 'post': if method == 'post':
r = requests.post(url, headers=self.headers, json=data) r = requests.post(url, headers=self.headers, json=data)
elif method == 'get': elif method == 'get':

@ -2,6 +2,7 @@ import requests
import six import six
import json import json
from decimal import Decimal from decimal import Decimal
from flask import current_app
from app import config from app import config
@ -18,6 +19,7 @@ class WalletRPC(object):
data=json.dumps({'method': method, 'params': params}), data=json.dumps({'method': method, 'params': params}),
auth=self.auth auth=self.auth
) )
current_app.logger.info(f'GET - {self.endpoint} - {method}')
if 'error' in r.json(): if 'error' in r.json():
return r.json()['error'] return r.json()['error']
else: else:

Loading…
Cancel
Save