fix: Try to run automation every 5 mins

This commit is contained in:
Nathan Woodburn 2024-03-15 14:59:07 +11:00
parent 171e891555
commit afd7ae2947
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -3,7 +3,7 @@ import account
import requests
import threading
import os
import datetime
import time
APIKEY = os.environ.get("hsd_api")
ip = os.getenv("hsd_ip")
@ -37,22 +37,21 @@ functions = {
}
}
started = 0
started = False
# Main entry point only lets the main function run every 5 mins
def automation(params, authentication):
global started
now = datetime.datetime.now().timestamp()
# Add 5 mins
now = now - 300
if now < started:
return {"Status": "Waiting before checking for new actions"}
started = datetime.datetime.now().timestamp()
if started:
return {"Status": "Auto Renews running"}
started = True
threading.Thread(target=automations_background, args=(authentication,)).start()
return {"Status": "Checking for actions"}
return {"Status": "Started Auto Renews"}
# Background function to run the automations
def automations_background(authentication):
while True:
print("Running automations")
# Get account details
account_name = account.check_account(authentication)
@ -79,3 +78,6 @@ def automations_background(authentication):
requests.post(f"http://x:{APIKEY}@{ip}:12039",json={"method": "sendbatch","params": [[["REDEEM"]]]})
except Exception as e:
print(e)
# Sleep for 5 mins before running again
time.sleep(300)