basic invites manager chronjob thing

This commit is contained in:
shockrah 2020-07-21 18:13:33 -07:00
parent 6a9f91429e
commit 1eed2f4027
3 changed files with 62 additions and 1 deletions

View File

@ -1,4 +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

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

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