jobs_helper.rb 956 B

12345678910111213141516171819202122232425262728293031323334353637
  1. module JobsHelper
  2. def status(job)
  3. case
  4. when job.failed_at
  5. content_tag :span, 'failed', class: 'label label-danger'
  6. when job.locked_at && job.locked_by
  7. content_tag :span, 'running', class: 'label label-info'
  8. else
  9. content_tag :span, 'queued', class: 'label label-warning'
  10. end
  11. end
  12. def relative_distance_of_time_in_words(time)
  13. if time < (now = Time.now)
  14. time_ago_in_words(time) + ' ago'
  15. else
  16. 'in ' + distance_of_time_in_words(time, now)
  17. end
  18. end
  19. # Given an queued job, parse the stored YAML to retrieve the ID of the Agent
  20. # meant to be ran.
  21. #
  22. # Can return nil, or an instance of Agent.
  23. def agent_from_job(job)
  24. if data = YAML.load(job.handler).try(:job_data)
  25. Agent.find_by_id(data['arguments'][0])
  26. else
  27. false
  28. end
  29. rescue ArgumentError
  30. # We can get to this point before all of the agents have loaded (usually,
  31. # in development)
  32. nil
  33. end
  34. end