worker-checker.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. $(function () {
  2. let sinceId = null;
  3. let previousJobs = null;
  4. if ($(".job-indicator").length) {
  5. var check = function () {
  6. const query = sinceId != null ? "?since_id=" + sinceId : "";
  7. return $.getJSON("/worker_status" + query, function (json) {
  8. for (var method of ["pending", "awaiting_retry", "recent_failures"]) {
  9. var count = json[method];
  10. var elem = $(`.job-indicator[role=${method}]`);
  11. if (count > 0) {
  12. var tooltipOptions = {
  13. title: `${count} jobs ${method.split("_").join(" ")}`,
  14. delay: 0,
  15. placement: "bottom",
  16. trigger: "hover",
  17. };
  18. if (elem.is(":visible")) {
  19. elem
  20. .tooltip("destroy")
  21. .tooltip(tooltipOptions)
  22. .find(".number")
  23. .text(count);
  24. } else {
  25. elem
  26. .tooltip("destroy")
  27. .tooltip(tooltipOptions)
  28. .fadeIn()
  29. .find(".number")
  30. .text(count);
  31. }
  32. } else {
  33. if (elem.is(":visible")) {
  34. elem.tooltip("destroy").fadeOut();
  35. }
  36. }
  37. }
  38. if (sinceId != null && json.event_count > 0) {
  39. $("#event-indicator")
  40. .tooltip("destroy")
  41. .tooltip({
  42. title: "Click to see the events",
  43. delay: 0,
  44. placement: "bottom",
  45. trigger: "hover",
  46. })
  47. .find("a")
  48. .attr({ href: json.events_url })
  49. .end()
  50. .fadeIn()
  51. .find(".number")
  52. .text(json.event_count);
  53. } else {
  54. $("#event-indicator").tooltip("destroy").fadeOut();
  55. }
  56. if (sinceId == null) {
  57. sinceId = json.max_id;
  58. }
  59. const currentJobs = [
  60. json.pending,
  61. json.awaiting_retry,
  62. json.recent_failures,
  63. ];
  64. if (
  65. document.location.pathname === "/jobs" &&
  66. $(".modal[aria-hidden=false]").length === 0 &&
  67. previousJobs != null &&
  68. previousJobs.join(",") !== currentJobs.join(",")
  69. ) {
  70. if (
  71. !document.location.search ||
  72. document.location.search === "?page=1"
  73. ) {
  74. $.get("/jobs", (data) => {
  75. return $("#main-content").html(data);
  76. });
  77. }
  78. }
  79. previousJobs = currentJobs;
  80. return (window.workerCheckTimeout = setTimeout(check, 2000));
  81. });
  82. };
  83. return check();
  84. }
  85. });