mirror of
https://github.com/Rushilwiz/spaceout.git
synced 2025-04-06 13:10:16 -04:00
Added Ping and Basic Exception Views
This commit is contained in:
parent
a2b4488bd9
commit
394a3be380
|
@ -6,6 +6,8 @@ name = "pypi"
|
|||
[packages]
|
||||
django = "*"
|
||||
djangorestframework = "*"
|
||||
django-cockroachdb = "*"
|
||||
psycopg2 = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
|
31
site/Pipfile.lock
generated
31
site/Pipfile.lock
generated
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "b890b2061eb6fc1d8bf94ed78d77990ac519683b06b3819184b0effc5cedbd47"
|
||||
"sha256": "1a0c4ca347340e98b3dd8bad3d296f6e9b6b6692d4324a552d79f5580ce192fe"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
@ -32,6 +32,14 @@
|
|||
"index": "pypi",
|
||||
"version": "==3.1.4"
|
||||
},
|
||||
"django-cockroachdb": {
|
||||
"hashes": [
|
||||
"sha256:8aefd50510ef793f3fbd7833f17175a7a14cb5b397b07a6ee203f3e6433f9112",
|
||||
"sha256:e4071ec7c90f24f11a47497aeb0b96567f2924ca350d86b1c4eaae40f13a408c"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==3.1.2"
|
||||
},
|
||||
"djangorestframework": {
|
||||
"hashes": [
|
||||
"sha256:0209bafcb7b5010fdfec784034f059d512256424de2a0f084cb82b096d6dd6a7"
|
||||
|
@ -39,6 +47,27 @@
|
|||
"index": "pypi",
|
||||
"version": "==3.12.2"
|
||||
},
|
||||
"psycopg2": {
|
||||
"hashes": [
|
||||
"sha256:00195b5f6832dbf2876b8bf77f12bdce648224c89c880719c745b90515233301",
|
||||
"sha256:068115e13c70dc5982dfc00c5d70437fe37c014c808acce119b5448361c03725",
|
||||
"sha256:26e7fd115a6db75267b325de0fba089b911a4a12ebd3d0b5e7acb7028bc46821",
|
||||
"sha256:2c93d4d16933fea5bbacbe1aaf8fa8c1348740b2e50b3735d1b0bf8154cbf0f3",
|
||||
"sha256:56007a226b8e95aa980ada7abdea6b40b75ce62a433bd27cec7a8178d57f4051",
|
||||
"sha256:56fee7f818d032f802b8eed81ef0c1232b8b42390df189cab9cfa87573fe52c5",
|
||||
"sha256:6a3d9efb6f36f1fe6aa8dbb5af55e067db802502c55a9defa47c5a1dad41df84",
|
||||
"sha256:a49833abfdede8985ba3f3ec641f771cca215479f41523e99dace96d5b8cce2a",
|
||||
"sha256:ad2fe8a37be669082e61fb001c185ffb58867fdbb3e7a6b0b0d2ffe232353a3e",
|
||||
"sha256:b8cae8b2f022efa1f011cc753adb9cbadfa5a184431d09b273fb49b4167561ad",
|
||||
"sha256:d160744652e81c80627a909a0e808f3c6653a40af435744de037e3172cf277f5",
|
||||
"sha256:d5062ae50b222da28253059880a871dc87e099c25cb68acf613d9d227413d6f7",
|
||||
"sha256:f22ea9b67aea4f4a1718300908a2fb62b3e4276cf00bd829a97ab5894af42ea3",
|
||||
"sha256:f974c96fca34ae9e4f49839ba6b78addf0346777b46c4da27a7bf54f48d3057d",
|
||||
"sha256:fb23f6c71107c37fd667cb4ea363ddeb936b348bbd6449278eb92c189699f543"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.8.6"
|
||||
},
|
||||
"pytz": {
|
||||
"hashes": [
|
||||
"sha256:3e6b7dd2d1e0a59084bcee14a17af60c5c562cdc16d828e8eba2e683d3a7e268",
|
||||
|
|
|
@ -1,3 +1,32 @@
|
|||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.views.generic import View
|
||||
from django.db import Error, OperationalError
|
||||
from psycopg2 import errorcodes
|
||||
from functools import wraps
|
||||
import time
|
||||
|
||||
|
||||
# Create your views here.
|
||||
def retry_on_exception(view, num_retries=3, on_failure=HttpResponse(status=500), delay_=0.5, backoff_=1.5):
|
||||
@wraps(view)
|
||||
def retry(*args, **kwargs):
|
||||
delay = delay_
|
||||
for i in range(num_retries):
|
||||
try:
|
||||
return view(*args, **kwargs)
|
||||
except OperationalError as ex:
|
||||
if i == num_retries - 1:
|
||||
return on_failure
|
||||
elif getattr(ex.__cause__, 'pgcode', '') == errorcodes.SERIALIZATION_FAILURE:
|
||||
time.sleep(delay)
|
||||
delay *= backoff_
|
||||
else:
|
||||
return on_failure
|
||||
except Error as ex:
|
||||
return on_failure
|
||||
return retry
|
||||
|
||||
|
||||
class PingView(View):
|
||||
def get(self, request, *args, **kwargs):
|
||||
return HttpResponse("python/django", status=200)
|
|
@ -37,6 +37,7 @@ INSTALLED_APPS = [
|
|||
'django.contrib.sessions',
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
'config',
|
||||
'rest_framework',
|
||||
'frontend',
|
||||
'api',
|
||||
|
@ -77,10 +78,21 @@ WSGI_APPLICATION = 'config.wsgi.application'
|
|||
# Database
|
||||
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
|
||||
|
||||
# DATABASES = {
|
||||
# 'default': {
|
||||
# 'ENGINE': 'django.db.backends.sqlite3',
|
||||
# 'NAME': BASE_DIR / 'db.sqlite3',
|
||||
# }
|
||||
# }
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': BASE_DIR / 'db.sqlite3',
|
||||
'ENGINE' : 'django_cockroachdb',
|
||||
'NAME' : 'spaceout',
|
||||
'USER' : 'spaceout',
|
||||
'PASSWORD': 'spaceout',
|
||||
'HOST' : 'localhost',
|
||||
'PORT' : 42035,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user