basic invites manager chronjob thing
This commit is contained in:
parent
6a9f91429e
commit
1eed2f4027
@ -1,4 +1,46 @@
|
|||||||
# Chronjob which is meant to remove old/unwanted invites from our database
|
# 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)
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
# Invites Manager
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
17
server/invites-manager/tests/clean.sh
Normal file
17
server/invites-manager/tests/clean.sh
Normal 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user