diff --git a/backend/src/app/controllers/job/get.ts b/backend/src/app/controllers/job/get.ts index dac24ac..82fc6d1 100644 --- a/backend/src/app/controllers/job/get.ts +++ b/backend/src/app/controllers/job/get.ts @@ -17,12 +17,12 @@ export default async (req: Request, res: Response) => { // Determine how many items in the queue are ahead of this one const aheadInQueue = await Jobs.find({ - queue_place: { $lt: job.queuePlace }, + queue_place: { $lte: job.queuePlace }, }); let text: string = ""; if (job.status == Status.ENQUEUED) { - text = `Enqueued: ${aheadInQueue.length} Job(s) ahead in queue`; + text = `Enqueued: ${aheadInQueue.length + 1} Job(s) ahead in queue`; } else if (job.status == Status.PROCESSING) { text = `Currently Processing\n${job.logs}`; } else if (job.status == Status.COMPLETE) { diff --git a/processor/src/x_fast_provider.py b/processor/src/x_fast_provider.py index 2f69d79..c3c55a7 100644 --- a/processor/src/x_fast_provider.py +++ b/processor/src/x_fast_provider.py @@ -10,8 +10,9 @@ from os import environ as env from os import unlink as rm from textwrap import dedent from typing import List -from urllib3.exceptions import ProtocolError + import requests +from urllib3.exceptions import ProtocolError, ReadTimeoutError import curse_api as cf from common import Job, Status @@ -90,37 +91,44 @@ class FastProvider(MgmtApiLogger): } ) - try: - response = requests.post( - "https://api.modrinth.com/v2/version", - timeout=30, - headers={"Authorization": self._job.github_pat}, - files=[ - ("data", (None, payload, None)), - ("files", (jar_fn, jar_data, "application/octet-stream")), - ], - ) - if response.status_code == 200: - statuses.append(Status.SUCCESS) - self.logmsg(f"✅ {display_nm}") - else: - statuses.append(Status.FAIL) - self.logmsg( - dedent( - f"""----- 🔥 {display_nm} ----- - API Response from Modrinth FAIL for {display_nm}: - {self.decode_modrinth_resp(response)} - """ - ).strip("\n") + tries, msg = 1, "" + while tries <= 5: + try: + response = requests.post( + "https://api.modrinth.com/v2/version", + timeout=30, + headers={"Authorization": self._job.github_pat}, + files=[ + ("data", (None, payload, None)), + ("files", (jar_fn, jar_data, "application/octet-stream")), + ], ) + if response.status_code == 200: + statuses.append(Status.SUCCESS) + self.logmsg(f"✅ {display_nm}") + else: + statuses.append(Status.FAIL) + self.logmsg( + dedent( + f"""----- 🔥 {display_nm} ----- + API Response from Modrinth FAIL for {display_nm}: + {self.decode_modrinth_resp(response)} + """ + ).strip("\n") + ) - rm(jar_fn) - except (ProtocolError, requests.exceptions.ChunkedEncodingError): - self.logmsg(f"🔥 Uploading {display_nm} to Modrinth failed, skipping..") - statuses.append(Status.FAIL) - continue - except TimeoutError: - self.logmsg(f"🕜 Timed out uploading {jar_fn}. Manual upload required") + rm(jar_fn) + break + except (ReadTimeoutError, TimeoutError): + tries += 1 + msg = f"🕜 Timed out uploading {jar_fn}. Manual upload required" + continue + except (ProtocolError, requests.exceptions.ChunkedEncodingError): + tries += 1 + msg = f"🔥 Uploading {display_nm} to Modrinth failed, skipping.." + continue + if tries == 5: + self.logmsg(msg) statuses.append(Status.FAIL) # endregion UPLOAD JAR FILE return statuses diff --git a/processor/src/x_slow_provider.py b/processor/src/x_slow_provider.py index 4b6effd..25d34e1 100644 --- a/processor/src/x_slow_provider.py +++ b/processor/src/x_slow_provider.py @@ -22,6 +22,7 @@ from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait +from urllib3.exceptions import ProtocolError, ReadTimeoutError from webdriver_manager.chrome import ChromeDriverManager import curse_api as cf @@ -212,35 +213,45 @@ class SlowProvider(MgmtApiLogger): } ) - try: - response = requests.post( - "https://api.modrinth.com/v2/version", - timeout=30, - headers={"Authorization": self._job.github_pat}, - files=[ - ("data", (None, payload, None)), - ("files", (fpath, jar_data, "application/octet-stream")), - ], - ) - if response.status_code == 200: - statuses.append(Status.SUCCESS) - self.logmsg(f"✅ {display_nm}") - else: - statuses.append(Status.FAIL) - self.logmsg( - dedent( - f"""----- 🔥 {display_nm} ----- - API Response from Modrinth FAIL for {display_nm}: - {self.decode_modrinth_resp(response)} - """ - ).strip("\n") + tries, msg = 1, "" + while tries <= 5: + try: + response = requests.post( + "https://api.modrinth.com/v2/version", + timeout=30, + headers={"Authorization": self._job.github_pat}, + files=[ + ("data", (None, payload, None)), + ("files", (fpath, jar_data, "application/octet-stream")), + ], ) + if response.status_code == 200: + statuses.append(Status.SUCCESS) + self.logmsg(f"✅ {display_nm}") + else: + statuses.append(Status.FAIL) + self.logmsg( + dedent( + f"""----- 🔥 {display_nm} ----- + API Response from Modrinth FAIL for {display_nm}: + {self.decode_modrinth_resp(response)} + """ + ).strip("\n") + ) - rm(f"./out/{self._job.curseforge_slug}/{fpath}") - except TimeoutError: - self.logmsg(f"🕜 Timed out uploading {fpath}. Manual upload required") + rm(f"./out/{self._job.curseforge_slug}/{fpath}") + break + except (ReadTimeoutError, TimeoutError): + tries += 1 + msg = f"🕜 Timed out uploading {fpath}. Manual upload required" + continue + except (ProtocolError, requests.exceptions.ChunkedEncodingError): + tries += 1 + msg = f"🔥 Uploading {display_nm} to Modrinth failed, skipping.." + continue + if tries == 5: + self.logmsg(msg) statuses.append(Status.FAIL) - # endregion UPLOAD THE MOD any_succ = len(list(filter(lambda x: x == Status.SUCCESS, statuses))) > 0