worker_status_controller.rb 978 B

1234567891011121314151617181920212223242526272829303132
  1. class WorkerStatusController < ApplicationController
  2. def show
  3. start = Time.now
  4. events = current_user.events
  5. if params[:since_id].present?
  6. since_id = params[:since_id].to_i
  7. events = events.where('id > ?', since_id)
  8. end
  9. result = events.select('COUNT(id) AS count', 'MIN(id) AS min_id', 'MAX(id) AS max_id').reorder('min(created_at)').first
  10. count, min_id, max_id = result.count, result.min_id, result.max_id
  11. case max_id
  12. when nil
  13. when min_id
  14. events_url = events_path(hl: max_id)
  15. else
  16. events_url = events_path(hl: "#{min_id}-#{max_id}")
  17. end
  18. render json: {
  19. pending: Delayed::Job.pending.where("run_at <= ?", start).count,
  20. awaiting_retry: Delayed::Job.awaiting_retry.count,
  21. recent_failures: Delayed::Job.failed.where('failed_at > ?', 5.days.ago).count,
  22. event_count: count,
  23. max_id: max_id || 0,
  24. events_url: events_url,
  25. compute_time: Time.now - start
  26. }
  27. end
  28. end