Module: SolidWebUi::Queue::ApplicationHelper
- Defined in:
- app/helpers/solid_web_ui/queue/application_helper.rb
Instance Method Summary collapse
-
#human_duration(seconds) ⇒ Object
Compact, sub-minute-precise duration: “1.2s”, “3m 04s”, “2h 01m”.
-
#job_duration(job) ⇒ Object
Best available execution time for a job.
-
#job_status(job) ⇒ Object
Status of a job derived from which execution table holds it.
- #queue_latency(queue) ⇒ Object
- #queue_nav(active) ⇒ Object
- #short_time(time) ⇒ Object
Instance Method Details
#human_duration(seconds) ⇒ Object
Compact, sub-minute-precise duration: “1.2s”, “3m 04s”, “2h 01m”.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/helpers/solid_web_ui/queue/application_helper.rb', line 47 def human_duration(seconds) return "—" if seconds.nil? seconds = seconds.to_f return format("%.1fs", seconds) if seconds < 60 if seconds < 3600 format("%dm %02ds", seconds / 60, seconds % 60) else format("%dh %02dm", seconds / 3600, (seconds % 3600) / 60) end end |
#job_duration(job) ⇒ Object
Best available execution time for a job. Solid Queue does not persist a job’s start time once it finishes (the claimed_execution row is deleted on finish), so:
- finished job → finished_at - created_at (total time in the system)
- claimed job → now - claimed_execution.created_at (live run time)
- anything else → nil (no meaningful duration yet)
38 39 40 41 42 43 44 |
# File 'app/helpers/solid_web_ui/queue/application_helper.rb', line 38 def job_duration(job) if job.finished_at? human_duration(job.finished_at - job.created_at) elsif job.claimed_execution human_duration(Time.current - job.claimed_execution.created_at) end end |
#job_status(job) ⇒ Object
Status of a job derived from which execution table holds it.
17 18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/solid_web_ui/queue/application_helper.rb', line 17 def job_status(job) return :finished if job.finished_at? return :failed if job.failed_execution return :blocked if job.blocked_execution return :in_progress if job.claimed_execution return :scheduled if job.scheduled_execution return :ready if job.ready_execution :unknown end |
#queue_latency(queue) ⇒ Object
28 29 30 |
# File 'app/helpers/solid_web_ui/queue/application_helper.rb', line 28 def queue_latency(queue) queue.respond_to?(:human_latency) ? queue.human_latency : queue.latency end |
#queue_nav(active) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/solid_web_ui/queue/application_helper.rb', line 5 def queue_nav(active) [ { label: "Dashboard", href: root_path, active: active == :dashboard }, { label: "Queues", href: queues_path, active: active == :queues }, { label: "Jobs", href: jobs_path, active: active == :jobs }, { label: "Failed", href: failed_executions_path, active: active == :failed }, { label: "Processes", href: processes_path, active: active == :processes }, { label: "Recurring", href: recurring_tasks_path, active: active == :recurring } ] end |
#short_time(time) ⇒ Object
60 61 62 63 64 |
# File 'app/helpers/solid_web_ui/queue/application_helper.rb', line 60 def short_time(time) return "—" if time.nil? time.in_time_zone(SolidWebUi::Queue.config.time_zone).strftime("%Y-%m-%d %H:%M:%S") end |