Add database reconnect
This commit is contained in:
parent
e154645972
commit
d9454f44d8
@ -1,8 +1,12 @@
|
||||
FROM python:3.13-slim
|
||||
|
||||
#ENV PYTHONPATH=/usr/lib/python3/dist-packages
|
||||
RUN python3 -m venv venv
|
||||
COPY requirements.txt ./
|
||||
RUN pip3 install -r requirements.txt
|
||||
RUN ./venv/bin/pip install --no-cache-dir -r requirements.txt
|
||||
#RUN pip3 install -r requirements.txt
|
||||
COPY *.py *.txt *.toml ./
|
||||
COPY inventory ./inventory
|
||||
CMD ["rio", "run", "--release", "--public", "--port", "8000"]
|
||||
#ENV PYTHONPATH=/inventory
|
||||
CMD ["./venv/bin/python3", "-m", "rio", "run", "--release", "--public", "--port", "8000"]
|
||||
EXPOSE 8000
|
@ -1,7 +1,12 @@
|
||||
from peewee import *
|
||||
from search import InventorySearch as ivs
|
||||
from playhouse.shortcuts import ReconnectMixin
|
||||
|
||||
db = MySQLDatabase('inventory', thread_safe=True, user='inventory', password='nfrwnfprifbwef', host='database', port=3306)
|
||||
class ReconnectMySQLDatabase(ReconnectMixin, MySQLDatabase):
|
||||
pass
|
||||
|
||||
# auto-reconnect if mysql disconnects
|
||||
db = ReconnectMySQLDatabase('inventory', thread_safe=True, user='inventory', password='nfrwnfprifbwef', host='database', port=3306)
|
||||
search = None
|
||||
|
||||
class user(Model):
|
||||
@ -144,7 +149,8 @@ def create_item(fullname, serial, officename, barcode, locationid=None, descript
|
||||
if loc == False:
|
||||
loc = None
|
||||
else:
|
||||
print("Found location: " + loc.name)
|
||||
pass
|
||||
#print("Found location: " + loc.name)
|
||||
off = office.select().where(office.name == officename)[0]
|
||||
itm = item(office=off, barcode=barcode, fullname=fullname, description=description, loc=loc, serial=serial, mac=mac, fwver=fwver, manufacturer=manufacturer)
|
||||
itm.save(force_insert=True)
|
||||
@ -156,7 +162,7 @@ def create_item(fullname, serial, officename, barcode, locationid=None, descript
|
||||
except:
|
||||
pass
|
||||
search.add_document(itmdict)
|
||||
print("item: " + itm.fullname)
|
||||
print("added item: " + itm.fullname)
|
||||
return itm
|
||||
except IntegrityError:
|
||||
print("Duplicate item " + fullname)
|
||||
@ -174,7 +180,8 @@ def update_item(fullname, serial, officename, barcode, locationid=None, descript
|
||||
if loc == False:
|
||||
loc = None
|
||||
else:
|
||||
print("Found location: " + loc.name)
|
||||
pass
|
||||
#print("Found location: " + loc.name)
|
||||
off = office.select().where(office.name == officename)[0]
|
||||
itm = item(office=off, barcode=barcode, fullname=fullname, description=description, loc=loc, serial=serial, mac=mac, fwver=fwver, manufacturer=manufacturer)
|
||||
itm.save()
|
||||
@ -186,7 +193,7 @@ def update_item(fullname, serial, officename, barcode, locationid=None, descript
|
||||
except:
|
||||
pass
|
||||
search.add_document(itmdict)
|
||||
print("item: " + itm.fullname)
|
||||
print("updated item: " + itm.fullname)
|
||||
return itm
|
||||
except IntegrityError:
|
||||
print("Duplicate item " + fullname)
|
||||
@ -215,7 +222,7 @@ def create_component(parentitem, name, barcode, serial=None, description=None):
|
||||
try:
|
||||
cmp = component(owner=itm, name=name, barcode=barcode, description=description, serial=serial)
|
||||
cmp.save(force_insert=True)
|
||||
print("component: " + cmp.name)
|
||||
print("added component: " + cmp.name)
|
||||
return cmp
|
||||
except IntegrityError:
|
||||
print("Duplicate component " + name)
|
||||
@ -347,6 +354,12 @@ def user_login(username, password):
|
||||
return user.password == password
|
||||
else:
|
||||
return False
|
||||
|
||||
def check_db_connection():
|
||||
query = office.select()
|
||||
if len(query) > 0:
|
||||
# require the query to fire by checking it's return length
|
||||
pass
|
||||
|
||||
def test():
|
||||
costa = create_user("Costa Aralis", "caralpwtwfpis", "12345")
|
||||
|
@ -75,3 +75,4 @@ app = rio.App(
|
||||
assets_dir=Path(__file__).parent / "assets",
|
||||
)
|
||||
|
||||
#app.run_as_web_server(host='0.0.0.0',port=8000)
|
@ -52,6 +52,7 @@ class BrowsePage(rio.Component):
|
||||
@rio.event.on_populate
|
||||
async def _search(self, query=searchtext):
|
||||
self.office = self.session[comps.Settings].office
|
||||
#print("Office:",self.office)
|
||||
self.filters['office'] = self.office
|
||||
|
||||
|
||||
|
@ -2,4 +2,5 @@ peewee
|
||||
pymysql
|
||||
rio-ui==0.10.4
|
||||
meilisearch #==0.31.5
|
||||
mac-vendor-lookup
|
||||
mac-vendor-lookup
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user