jobs_helper.rb 928 B

1234567891011121314151617181920212223242526272829303132333435
  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. begin
  25. Agent.find_by_id(YAML.load(job.handler).job_data['arguments'][0])
  26. rescue ArgumentError
  27. # We can get to this point before all of the agents have loaded (usually,
  28. # in development)
  29. nil
  30. end
  31. end
  32. end