Moved invites manager to its own directory at the root

This commit is contained in:
shockrah
2020-08-22 15:51:20 -07:00
parent 016d81b82b
commit afcc03959a
8 changed files with 5 additions and 5 deletions

2
invites-manager/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
./bin/*
./lib/*

View File

@@ -0,0 +1,46 @@
# Chronjob which is meant to remove old/unwanted invites from our database
import mysql.connector as mysql
from os import getenv
import time, sys
code_name = 'INVITES_MANAGER'
def remove_old(config):
global code_name
'''
Removes invites that are out of date
'''
now = int(time.time())
query = ('DELETE FROM invites WHERE expires < ?')
conn = mysql.connect(**config)
cursor = conn.cursor(prepared=True)
cursor.execute(query, (now,))
cursor.close()
conn.close()
print(f'[ {code_name} ] : Removed old invites with no errors')
if __name__ == '__main__':
fail = False
config = {
'database': getenv('DATABASE_NAME'),
'password': getenv('DATABASE_PASS'),
'user': getenv('DATABASE_USER'),
'host': getenv('DATABASE_HOST'),
'port': int(getenv('DATABASE_PORT')),
}
for k in config:
if config[k] is None:
print(f'[ {code_name} ] : {k} not set', file=sys.stderr)
fail = True
if not fail:
remove_old(config)
else:
exit(1)

View File

@@ -0,0 +1,8 @@
home = /usr
implementation = CPython
version_info = 3.8.5.final.0
virtualenv = 20.0.20
include-system-site-packages = false
base-prefix = /usr
base-exec-prefix = /usr
base-executable = /usr/bin/python3

View File

@@ -0,0 +1,6 @@
# Invites Manager
Chron-job which runs every few minutes to clean out invites table from our invites table

View File

@@ -0,0 +1,3 @@
mysql-connector-python==8.0.21
protobuf==3.12.2
six==1.15.0

View File

@@ -0,0 +1,17 @@
#!/bin/sh
# Simple test to make sure we can actually remove stuff from mysql
# without the whole thing complaining about everything
. ./bin/activate
export DATABASE_URL=mysql://freechat_dev:password@localhost:3306/freechat
export DATABASE_NAME=freechat
export DATABASE_PASS=password
export DATABASE_USER=freechat_dev
export DATABASE_HOST=localhost
export DATABASE_PORT=3306
python invites-routine.py