Add database reconnect
This commit is contained in:
		@@ -1,8 +1,12 @@
 | 
				
			|||||||
FROM python:3.13-slim
 | 
					FROM python:3.13-slim
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ENV PYTHONPATH=/usr/lib/python3/dist-packages
 | 
				
			||||||
 | 
					RUN python3 -m venv venv
 | 
				
			||||||
COPY requirements.txt ./
 | 
					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 *.py *.txt *.toml ./
 | 
				
			||||||
COPY inventory ./inventory
 | 
					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
 | 
					EXPOSE 8000
 | 
				
			||||||
@@ -1,7 +1,12 @@
 | 
				
			|||||||
from peewee import *
 | 
					from peewee import *
 | 
				
			||||||
from search import InventorySearch as ivs
 | 
					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 
 | 
					search = None 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class user(Model):
 | 
					class user(Model):
 | 
				
			||||||
@@ -144,7 +149,8 @@ def create_item(fullname, serial, officename, barcode, locationid=None, descript
 | 
				
			|||||||
        if loc == False:
 | 
					        if loc == False:
 | 
				
			||||||
            loc = None
 | 
					            loc = None
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            print("Found location: " + loc.name)
 | 
					            pass
 | 
				
			||||||
 | 
					            #print("Found location: " + loc.name)
 | 
				
			||||||
        off = office.select().where(office.name == officename)[0]
 | 
					        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 = item(office=off, barcode=barcode, fullname=fullname, description=description, loc=loc, serial=serial, mac=mac, fwver=fwver, manufacturer=manufacturer)
 | 
				
			||||||
        itm.save(force_insert=True)
 | 
					        itm.save(force_insert=True)
 | 
				
			||||||
@@ -156,7 +162,7 @@ def create_item(fullname, serial, officename, barcode, locationid=None, descript
 | 
				
			|||||||
        except:
 | 
					        except:
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
        search.add_document(itmdict) 
 | 
					        search.add_document(itmdict) 
 | 
				
			||||||
        print("item: " + itm.fullname)
 | 
					        print("added item: " + itm.fullname)
 | 
				
			||||||
        return itm
 | 
					        return itm
 | 
				
			||||||
    except IntegrityError:
 | 
					    except IntegrityError:
 | 
				
			||||||
        print("Duplicate item " + fullname)
 | 
					        print("Duplicate item " + fullname)
 | 
				
			||||||
@@ -174,7 +180,8 @@ def update_item(fullname, serial, officename, barcode, locationid=None, descript
 | 
				
			|||||||
        if loc == False:
 | 
					        if loc == False:
 | 
				
			||||||
            loc = None
 | 
					            loc = None
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            print("Found location: " + loc.name)
 | 
					            pass
 | 
				
			||||||
 | 
					            #print("Found location: " + loc.name)
 | 
				
			||||||
        off = office.select().where(office.name == officename)[0]
 | 
					        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 = item(office=off, barcode=barcode, fullname=fullname, description=description, loc=loc, serial=serial, mac=mac, fwver=fwver, manufacturer=manufacturer)
 | 
				
			||||||
        itm.save()
 | 
					        itm.save()
 | 
				
			||||||
@@ -186,7 +193,7 @@ def update_item(fullname, serial, officename, barcode, locationid=None, descript
 | 
				
			|||||||
        except:
 | 
					        except:
 | 
				
			||||||
            pass
 | 
					            pass
 | 
				
			||||||
        search.add_document(itmdict) 
 | 
					        search.add_document(itmdict) 
 | 
				
			||||||
        print("item: " + itm.fullname)
 | 
					        print("updated item: " + itm.fullname)
 | 
				
			||||||
        return itm
 | 
					        return itm
 | 
				
			||||||
    except IntegrityError:
 | 
					    except IntegrityError:
 | 
				
			||||||
        print("Duplicate item " + fullname)
 | 
					        print("Duplicate item " + fullname)
 | 
				
			||||||
@@ -215,7 +222,7 @@ def create_component(parentitem, name, barcode, serial=None, description=None):
 | 
				
			|||||||
    try:
 | 
					    try:
 | 
				
			||||||
        cmp = component(owner=itm, name=name, barcode=barcode, description=description, serial=serial)
 | 
					        cmp = component(owner=itm, name=name, barcode=barcode, description=description, serial=serial)
 | 
				
			||||||
        cmp.save(force_insert=True)
 | 
					        cmp.save(force_insert=True)
 | 
				
			||||||
        print("component: " + cmp.name)
 | 
					        print("added component: " + cmp.name)
 | 
				
			||||||
        return cmp
 | 
					        return cmp
 | 
				
			||||||
    except IntegrityError:
 | 
					    except IntegrityError:
 | 
				
			||||||
        print("Duplicate component " + name)
 | 
					        print("Duplicate component " + name)
 | 
				
			||||||
@@ -348,6 +355,12 @@ def user_login(username, password):
 | 
				
			|||||||
    else:
 | 
					    else:
 | 
				
			||||||
        return False
 | 
					        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():
 | 
					def test():
 | 
				
			||||||
    costa = create_user("Costa Aralis", "caralpwtwfpis", "12345")
 | 
					    costa = create_user("Costa Aralis", "caralpwtwfpis", "12345")
 | 
				
			||||||
    costa.username = "caralis"
 | 
					    costa.username = "caralis"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -75,3 +75,4 @@ app = rio.App(
 | 
				
			|||||||
    assets_dir=Path(__file__).parent / "assets",
 | 
					    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
 | 
					    @rio.event.on_populate
 | 
				
			||||||
    async def _search(self, query=searchtext):
 | 
					    async def _search(self, query=searchtext):
 | 
				
			||||||
        self.office = self.session[comps.Settings].office
 | 
					        self.office = self.session[comps.Settings].office
 | 
				
			||||||
 | 
					        #print("Office:",self.office)
 | 
				
			||||||
        self.filters['office'] = self.office
 | 
					        self.filters['office'] = self.office
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,3 +3,4 @@ pymysql
 | 
				
			|||||||
rio-ui==0.10.4
 | 
					rio-ui==0.10.4
 | 
				
			||||||
meilisearch   #==0.31.5
 | 
					meilisearch   #==0.31.5
 | 
				
			||||||
mac-vendor-lookup
 | 
					mac-vendor-lookup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user