Added deletion of dead servers (downs>=purge_days)

This commit is contained in:
spla 2022-03-08 09:44:03 +01:00
pare 13fd0434de
commit f21e3f8461

Veure arxiu

@ -86,6 +86,32 @@ def dead():
return dead_lst return dead_lst
def delete_deads():
conn = None
try:
conn = psycopg2.connect(database = cleanserver_db, user = cleanserver_db_user, password = "", host = "/var/run/postgresql", port = "5432")
cur = conn.cursor()
cur.execute("delete from peers where downs >=(%s)", (purge_days,))
conn.commit()
cur.close()
except (Exception, psycopg2.DatabaseError) as error:
print(error)
finally:
if conn is not None:
conn.close()
def write_server(server, alive, checked): def write_server(server, alive, checked):
cleanserver_db, cleanserver_db_user = dbconfig() cleanserver_db, cleanserver_db_user = dbconfig()
@ -302,6 +328,12 @@ if __name__ == '__main__':
servers_count+=1 servers_count+=1
########################################## ##########################################
# delete dead servers old than purge_days
delete_deads()
##########################################
# get current hostname peers
user_agent = {'User-agent': 'Mozilla/5.0'} user_agent = {'User-agent': 'Mozilla/5.0'}