fixing bugs in btcpay server down detection

This commit is contained in:
forest 2022-02-22 14:17:40 -06:00
parent 32cb14f979
commit 6c57e45cdd
4 changed files with 14 additions and 12 deletions

View File

@ -143,7 +143,7 @@ else:
app.config['HTTP_CLIENT'] = MyHTTPClient(timeout_seconds=int(app.config['INTERNAL_HTTP_TIMEOUT_SECONDS']))
if app.config['BTCPAY_URL'] != "":
try_reconnnect_btcpay()
try_reconnnect_btcpay(app)
# only start the scheduler and attempt to migrate the database if we are running the app.
# otherwise we are running a CLI command.

View File

@ -1,4 +1,5 @@
import stripe
import requests
import json
import time
import decimal
@ -58,7 +59,7 @@ def btcpay_payment():
flash("BTCPay is not enabled on this server")
return redirect(url_for("console.account_balance"))
elif 'BTCPAY_CLIENT' not in current_app.config:
if not try_reconnnect_btcpay():
if not try_reconnnect_btcpay(current_app):
flash("can't contact the BTCPay server right now")
return redirect(url_for("console.account_balance"))
@ -100,7 +101,7 @@ def btcpay_payment():
def poll_btcpay_session(invoice_id):
if 'BTCPAY_CLIENT' not in current_app.config:
if not try_reconnnect_btcpay():
if not try_reconnnect_btcpay(current_app):
return [503, "can't contact btcpay server"]
invoice = None
@ -139,17 +140,17 @@ def poll_btcpay_session(invoice_id):
return [200, "ok"]
def try_reconnnect_btcpay():
def try_reconnnect_btcpay(app):
try:
response = requests.get(current_app.config['BTCPAY_URL'])
response = requests.get(app.config['BTCPAY_URL'])
if response.status_code == 200:
current_app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=current_app.config['BTCPAY_URL'], pem=current_app.config['BTCPAY_PRIVATE_KEY'])
app.config['BTCPAY_CLIENT'] = btcpay.Client(api_uri=app.config['BTCPAY_URL'], pem=app.config['BTCPAY_PRIVATE_KEY'])
return True
else:
current_app.logger.warn(f"Can't reach BTCPAY_URL {current_app.config['BTCPAY_URL']}: Response status code: {response.status_code}. Capsul will work fine except cryptocurrency payments will not work.")
app.logger.warn(f"Can't reach BTCPAY_URL {app.config['BTCPAY_URL']}: Response status code: {response.status_code}. Capsul will work fine except cryptocurrency payments will not work.")
return False
except:
current_app.logger.warn("unable to create btcpay client. Capsul will work fine except cryptocurrency payments will not work. The error was: " + my_exec_info_message(sys.exc_info()))
app.logger.warn("unable to create btcpay client. Capsul will work fine except cryptocurrency payments will not work. The error was: " + my_exec_info_message(sys.exc_info()))
return False

View File

@ -53,9 +53,6 @@ a:hover, a:active, a:visited {
.error {
color: rgb(173, 74, 8);
font-weight: bold;
border: 1px dashed rgb(173, 74, 8);
border-radius: 0.5em;
padding: 1em;
}
.disabled {

View File

@ -52,7 +52,11 @@
{% else %}
<li>
<span class="disabled">Add funds with Bitcoin/Litecoin/Monero (btcpay)</span>
<span class="error"> ERROR: the BTCPay server cannot be reached</span>
<ul>
<li>
<span class="error"> ERROR: the BTCPay server cannot be reached</span>
</li>
</ul>
</li>
{% endif %}