setup_logs_queue.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env python3
  2. """Show queued executions on the logs queue page."""
  3. import time
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. _QUEUE_ACTIONS_JS = """
  7. const done = arguments[arguments.length - 1];
  8. const title = arguments[0];
  9. const count = arguments[1];
  10. function bindingIdForTitle(actionTitle) {
  11. const button = document.querySelector('[title="' + actionTitle + '"]');
  12. if (!button) {
  13. throw new Error('Action button not found: ' + actionTitle);
  14. }
  15. return button.closest('.action-button').id.replace('actionButton-', '');
  16. }
  17. function uniqueTrackingId() {
  18. if (window.isSecureContext && window.crypto?.randomUUID) {
  19. return window.crypto.randomUUID();
  20. }
  21. return 'doc-screenshot-' + Date.now() + '-' + Math.random();
  22. }
  23. async function queueActions() {
  24. const bindingId = bindingIdForTitle(title);
  25. for (let i = 0; i < count; i++) {
  26. await window.client.startAction({
  27. bindingId: bindingId,
  28. arguments: [],
  29. uniqueTrackingId: uniqueTrackingId(),
  30. });
  31. }
  32. }
  33. queueActions().then(() => done(true)).catch((err) => done(String(err)));
  34. """
  35. def _wait_for_dashboard(driver, timeout=15):
  36. WebDriverWait(driver, timeout).until(
  37. lambda d: bool(d.find_element(By.TAG_NAME, "body").get_attribute("loaded-dashboard"))
  38. )
  39. WebDriverWait(driver, timeout).until(
  40. lambda d: d.execute_script("return !!window.client")
  41. )
  42. def run(driver):
  43. _wait_for_dashboard(driver)
  44. driver.execute_async_script(_QUEUE_ACTIONS_JS, "Slow backup", 3)
  45. time.sleep(1)
  46. driver.execute_script("window.location.href = '/logs/queue'")
  47. WebDriverWait(driver, 15).until(
  48. lambda d: len(d.find_elements(By.CSS_SELECTOR, ".queue-action-group-section")) >= 1
  49. )
  50. WebDriverWait(driver, 15).until(
  51. lambda d: len(d.find_elements(By.CSS_SELECTOR, ".queue-position")) >= 1
  52. )
  53. time.sleep(0.2)