worker-checker.js.coffee 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. $ ->
  2. firstEventCount = null
  3. previousJobs = null
  4. if $(".job-indicator").length
  5. check = ->
  6. $.getJSON "/worker_status", (json) ->
  7. for method in ['pending', 'awaiting_retry', 'recent_failures']
  8. count = json[method]
  9. elem = $(".job-indicator[role=#{method}]")
  10. if count > 0
  11. tooltipOptions = {
  12. title: "#{count} jobs #{method.split('_').join(' ')}"
  13. delay: 0
  14. placement: "bottom"
  15. trigger: "hover"
  16. }
  17. if elem.is(":visible")
  18. elem.tooltip('destroy').tooltip(tooltipOptions).find(".number").text(count)
  19. else
  20. elem.tooltip('destroy').tooltip(tooltipOptions).fadeIn().find(".number").text(count)
  21. else
  22. if elem.is(":visible")
  23. elem.tooltip('destroy').fadeOut()
  24. firstEventCount = json.event_count unless firstEventCount?
  25. if firstEventCount? && json.event_count > firstEventCount
  26. $("#event-indicator").tooltip('destroy').
  27. tooltip(title: "Click to reload", delay: 0, placement: "bottom", trigger: "hover").
  28. fadeIn().
  29. find(".number").
  30. text(json.event_count - firstEventCount)
  31. else
  32. $("#event-indicator").tooltip('destroy').fadeOut()
  33. currentJobs = [json.pending, json.awaiting_retry, json.recent_failures]
  34. if document.location.pathname == '/jobs' && $(".modal[aria-hidden=false]").length == 0 && previousJobs? && previousJobs.join(',') != currentJobs.join(',')
  35. $.get '/jobs', (data) =>
  36. $("#main-content").html(data)
  37. previousJobs = currentJobs
  38. window.workerCheckTimeout = setTimeout check, 2000
  39. check()
  40. $("#event-indicator a").on "click", (e) ->
  41. e.preventDefault()
  42. window.location.reload()