worker-checker.js.coffee 2.0 KB

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