Commit aa0e252d by Luciano Barletta

cleaning is now more robust, restarting service is safer

1 parent c252d8fb
...@@ -123,11 +123,15 @@ def clean(): ...@@ -123,11 +123,15 @@ def clean():
now = datetime.datetime.now() now = datetime.datetime.now()
for folder in paths: for folder in paths:
# carpeta no existe, borrar mensaje
if not os.path.exists(folder):
p.deletepath(folder)
continue
mtime = os.path.getmtime(folder) mtime = os.path.getmtime(folder)
# Si la carpeta existe por más de X segundos, borrala # Si la carpeta existe por más de X segundos, borrala
if int(now.strftime("%Y%m%d%H%M%S")) - int(time.strftime("%Y%m%d%H%M%S")) > operation_timer: if int(now.strftime("%Y%m%d%H%M%S")) - int(time.strftime("%Y%m%d%H%M%S")) > operation_timer:
if os.path.exists(folder): os.system("rm -r " + folder)
os.system("rm -r " + folder)
threading.Timer(clean_timer, clean).start() threading.Timer(clean_timer, clean).start()
...@@ -140,8 +144,7 @@ if __name__ == "__main__": ...@@ -140,8 +144,7 @@ if __name__ == "__main__":
attempt() attempt()
# Demonio clean # Demonio clean
clean() clean()
# Borro y creo msg/ por limpieza # creo msg/ si no existe
if os.path.exists(msgfolder): if not os.path.exists(msgfolder):
os.system("rm -r " + msgfolder) os.mkdir(msgfolder)
os.mkdir(msgfolder)
app.run("0.0.0.0") app.run("0.0.0.0")
\ No newline at end of file \ No newline at end of file
...@@ -111,4 +111,7 @@ class Process: ...@@ -111,4 +111,7 @@ class Process:
paths = [] paths = []
for row in rows: for row in rows:
paths.append(row[0]) paths.append(row[0])
return paths
\ No newline at end of file \ No newline at end of file
return paths
def deletepath(self,path):
self.conn.query("DELETE FROM msg WHERE path = ?",(path,))
\ No newline at end of file \ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!