feat: enhance setupStats function with retry logic and improve error handling; update entrypoint to run main script as PID 1
All checks were successful
Build and Push Docker Image / build (push) Successful in 12m29s
All checks were successful
Build and Push Docker Image / build (push) Successful in 12m29s
This commit is contained in:
21
main.py
21
main.py
@@ -181,19 +181,22 @@ def convert_to_bytes(down, downUnit):
|
|||||||
return float(down) * (1024 ** {'B': 0, 'KB': 1, 'MB': 2, 'GB': 3}[downUnit])
|
return float(down) * (1024 ** {'B': 0, 'KB': 1, 'MB': 2, 'GB': 3}[downUnit])
|
||||||
|
|
||||||
@yaspin()
|
@yaspin()
|
||||||
def setupStats(driver: webdriver.Remote, url: str):
|
def setupStats(driver: webdriver.Remote, url: str, retries: int = 5) -> webdriver.Remote:
|
||||||
logger.log(logging.INFO, 'Setting up stats.')
|
logger.log(logging.INFO, 'Setting up stats.')
|
||||||
actions = ActionChains(driver)
|
actions = ActionChains(driver)
|
||||||
wait = WebDriverWait(driver, 30, poll_frequency=0.2)
|
wait = WebDriverWait(driver, 30, poll_frequency=0.2)
|
||||||
|
|
||||||
driver.get(url)
|
for attempt in range(retries):
|
||||||
|
driver.get(url)
|
||||||
try:
|
try:
|
||||||
wait.until(ec.presence_of_element_located((By.CLASS_NAME, 'vjs-big-play-button')))
|
wait.until(ec.presence_of_element_located((By.CLASS_NAME, 'vjs-big-play-button')))
|
||||||
except Exception:
|
break
|
||||||
logger.error('Timeout while waiting for the big play button to be present.')
|
except Exception:
|
||||||
driver.quit()
|
logger.error(f'Timeout while waiting for the big play button to be present. Attempt {attempt + 1} of {retries}')
|
||||||
raise SystemExit(1)
|
if attempt == retries - 1:
|
||||||
|
logger.error('Timeout limit reached. Exiting.')
|
||||||
|
driver.quit()
|
||||||
|
raise SystemExit(1)
|
||||||
|
|
||||||
actions.click(driver.find_element(By.CLASS_NAME ,'video-js')).perform()
|
actions.click(driver.find_element(By.CLASS_NAME ,'video-js')).perform()
|
||||||
wait.until(ec.visibility_of_element_located((By.CLASS_NAME, 'vjs-control-bar')))
|
wait.until(ec.visibility_of_element_located((By.CLASS_NAME, 'vjs-control-bar')))
|
||||||
|
@@ -48,6 +48,8 @@ done
|
|||||||
|
|
||||||
printf '\n'
|
printf '\n'
|
||||||
|
|
||||||
# Start the Telegraf agent and the main script
|
# Start the Telegraf agent
|
||||||
telegraf --config ./telegraf.conf &
|
telegraf --config ./telegraf.conf &
|
||||||
./venv/bin/python main.py
|
|
||||||
|
# Start the main Python script as PID 1
|
||||||
|
exec ./venv/bin/python main.py
|
Reference in New Issue
Block a user