Browse Source

Initial support for submitting results, clearing temporary files

pull/3/head
tech234a 3 years ago
parent
commit
300a851c76
1 changed files with 26 additions and 7 deletions
  1. +26
    -7
      worker.py

+ 26
- 7
worker.py View File

@@ -3,6 +3,8 @@ from time import sleep
from os import mkdir
from json import dumps

from shutil import make_archive, rmtree

from discovery import getmetadata
from export import getsubs

@@ -23,12 +25,13 @@ while True:
else:
print("Error in retrieving ID, will attempt again in 10 minutes")
sleep(600)
try:
mkdir("out")
except:
pass

while True:
try:
mkdir("out")
except:
pass

recvids = set()
recchans = set()
recmixes = set()
@@ -90,8 +93,22 @@ while True:
print("Error in retrieving subtitles, waiting 10 minutes")
sleep(600)

# TODO: put the data somewhere...
# TODO: put the discoveries somewhere...
# TODO: put the data somewhere...
# TODO: put the discoveries somewhere...
open("out/discoveries.json", "w").write(dumps({"recvids": sorted(recvids), "recchans": sorted(recchans), "recmixes": sorted(recmixes), "recplayl": sorted(recplayl)}))

make_archive("out.zip", "zip", "out") #check this

while True:
try:
uploadr = requests.post("https://transfersh.com/"+str(batchinfo["batchID"])+".zip", data=open("out.zip"))
if uploadr.status_code == 200:
resulturl = uploadr.text
break
except BaseException as e:
print(e)
print("Encountered error in uploading results... retrying in 10 minutes")
sleep(600)

# Report the batch as complete (I can't think of a fail condition except for a worker exiting...)
# TODO: handle worker exit
@@ -102,6 +119,7 @@ while True:
("batchID", batchinfo["batchID"]),
("randomKey", batchinfo["randomKey"]),
("status", "c"),
("resulturl", resulturl),
)
statusrequest = requests.get(SERVER_BASE_URL+"/worker/updateStatus", params=params)

@@ -111,4 +129,5 @@ while True:
print("Error in reporting success, will attempt again in 10 minutes")
sleep(600)

# TODO: clear the output directory
# TODO: clear the output directory
rmtree("out")

Loading…
Cancel
Save