Skip to content

Commit

Permalink
Merge pull request #28 from agarbato/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
agarbato authored Aug 7, 2022
2 parents 5701e67 + 29b35e8 commit 32cc656
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
scheduler.add_job(func=scheduler_tasks_update_home_assistant_shares, trigger="interval", seconds=home_assistant_push_interval, args=(app,))
scheduler.add_job(func=scheduler_tasks_share_update_size, trigger="interval", hours=6, args=(app,))
scheduler.add_job(func=scheduler_tasks_purge_logs, trigger="interval", hours=12, args=(app,))
scheduler.add_job(func=scheduler_tasks_remove_locks, trigger="interval", minutes=15, args=(f"{root_dir}/.unison",))

scheduler.start()

Expand Down
13 changes: 13 additions & 0 deletions app/scheduler_tasks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
import json
import os
from homestats import *
from client_mgt import ClientMgt
from share_mgt import ShareMgt
Expand Down Expand Up @@ -111,3 +112,15 @@ def scheduler_tasks_purge_logs(app):
else:
print("Not reached max log events yet : %d" % int(max_log_events))


def scheduler_tasks_remove_locks(directory):
print(f"{strftime(time_format)} - Scheduled task: Remove Lock files")
now = time.time()
olderthreshold = 7200
files_in_directory = os.listdir(directory)
filtered_files = [file for file in files_in_directory if file.startswith("lk")]
for file in filtered_files:
filestamp = os.stat(os.path.join(directory, file)).st_mtime
filecompare = now - olderthreshold
if filestamp < filecompare:
os.remove(f"{directory}/{file}")
9 changes: 9 additions & 0 deletions app_client/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
import requests
import os
from conf import *
from apscheduler.schedulers.background import BlockingScheduler
from datetime import datetime
Expand Down Expand Up @@ -73,7 +74,15 @@ def end_sync(result, start_ts, log):
log.header()


def remove_lock(directory):
files_in_directory = os.listdir(directory)
filtered_files = [file for file in files_in_directory if file.startswith("lk")]
for file in filtered_files:
os.remove(f"{directory}/{file}")


def scheduler_sync():
remove_lock(f"{root_dir}/.unison")
log = Log(logfile)
start_ts = get_ts()
result = start_sync(log, start_ts)
Expand Down
7 changes: 7 additions & 0 deletions start/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ def test_connection():
return cmd


def remove_lock():
print("Check for lock files from previous interrupted sync")
command = f"if [ -f {unison_dir}/lk* ] ; then rm -f {unison_dir}/lk* ; fi ; echo $?"
ShellCmd(command)


def client_conf(role):
print("Exporting environment variables to client app..")
context = {
Expand Down Expand Up @@ -365,6 +371,7 @@ def exit_screen(status, error="None", role="None"):
conn = test_connection()
if conn:
client_conf(role)
remove_lock()
exit_screen("client_ok", "None", role)
else:
exit_screen("client_ko")
Expand Down

0 comments on commit 32cc656

Please sign in to comment.