Sha256: 24dba62beb884cb268e015e3a4382ce148875030dd2208211599f26b0d24aa48
Contents?: true
Size: 1.25 KB
Versions: 3
Compression:
Stored size: 1.25 KB
Contents
class JobsController < ApplicationController def index authorize! :show, :jobs jobs_by_name = $scheduler.jobs.each_with_object({}) { |job, map| map[job.tags.first] = { name: job.tags.first, schedule: job.original } } jobs = Job.where(name: jobs_by_name.keys) most_recent_jobs = jobs.joins(<<-SQL) inner join (select name, max(started_at) "started_at" from jobs group by name) "most_recent" on jobs.name=most_recent.name and jobs.started_at=most_recent.started_at SQL most_recent_jobs.each do |job| jobs_by_name[job.name][:last] = job end jobs.group(:name).unscope(:order).pluck(:name, "COUNT(id)", "COUNT(CASE WHEN succeeded THEN 1 ELSE NULL END)", "AVG(EXTRACT(epoch from finished_at - started_at))").each do |name, runs, successful_runs, avg_duration| jobs_by_name[name].merge!( runs: runs, successful_runs: successful_runs, avg_duration: avg_duration ) end @jobs = jobs_by_name.values end def show authorize! :show, :jobs @job_name = params[:slug] @jobs = Job.where(name: @job_name).preload(:error) end def run authorize! :run, :jobs Houston.jobs.run params[:slug] redirect_to "/jobs", notice: "#{params[:slug]} is running" end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
houston-core-0.7.0.beta3 | app/controllers/jobs_controller.rb |
houston-core-0.7.0.beta2 | app/controllers/jobs_controller.rb |
houston-core-0.7.0.beta | app/controllers/jobs_controller.rb |