-
-
Save cwsaylor/7573954 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveAdmin.register_page "Dashboard" do | |
menu :priority => 1, :label => proc{ I18n.t("active_admin.dashboard") } | |
content :title => proc{ I18n.t("active_admin.dashboard") } do | |
now = Time.now.getgm | |
columns do | |
column do | |
panel "Users" do | |
ul do | |
li do | |
users = User.all.count(:id) | |
link_to "#{users} registered users", admin_users_path, style: 'color: hsl(40, 100%, 40%)' | |
end | |
li do | |
users = User.where("confirmed_at is not null").count(:id) | |
link_to "#{users} confirmed users", admin_users_path(q: {confirmed_at_is_not_null: true}), style: 'color: green' | |
end | |
end | |
end | |
end # column | |
column do | |
panel "Jobs" do | |
ul do | |
li do | |
jobs = Delayed::Job.where("failed_at is not null").count(:id) | |
link_to "#{jobs} failing jobs", admin_jobs_path(q: {failed_at_is_not_null: true}), style: 'color: red' | |
end | |
li do | |
jobs = Delayed::Job.where("run_at <= ?", now).count(:id) | |
link_to "#{jobs} late jobs", admin_jobs_path(q: {run_at_lte: now.to_s(:db)}), style: 'color: hsl(40, 100%, 40%)' | |
end | |
li do | |
jobs = Delayed::Job.where("run_at >= ?", now).count(:id) | |
link_to "#{jobs} scheduled jobs", admin_jobs_path(q: {run_at_gte: now.to_s(:db)}), style: 'color: green' | |
end | |
end | |
end | |
end # column | |
end # columns | |
end # content | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveAdmin.register Delayed::Job, as: 'Job' do | |
#menu parent: 'Admin' | |
actions :index, :show, :edit, :update, :destroy | |
scope :success, default: true do |items| | |
items.where('failed_at is NULL') | |
end | |
scope :failed do |items| | |
items.where('failed_at IS NOT NULL') | |
end | |
index do | |
column :id | |
column :queue | |
column :priority | |
column :attempts | |
column :failed_at | |
column :run_at | |
column :created_at | |
column :locked_by | |
column :locked_at | |
default_actions | |
end | |
form do |f| | |
f.inputs "Scheduling" do | |
f.input :priority | |
f.input :queue | |
f.input :run_at | |
end | |
f.inputs "Details" do | |
f.input :id, input_html: {disabled: true} | |
f.input :created_at, input_html: {disabled: true} | |
f.input :updated_at, input_html: {disabled: true} | |
f.input :handler, input_html: {disabled: true} | |
end | |
f.inputs "Diagnostics" do | |
f.input :attempts, input_html: {disabled: true} | |
f.input :failed_at, input_html: {disabled: true} | |
f.input :last_error, input_html: {disabled: true} | |
f.input :locked_at, input_html: {disabled: true} | |
f.input :locked_by, input_html: {disabled: true} | |
end | |
f.buttons | |
end | |
action_item :only => [:edit] do | |
link_to 'Delete Job', admin_job_path(resource), | |
'data-method' => :delete, 'data-confirm' => 'Are you sure?' | |
end | |
action_item :only => [:show, :edit] do | |
link_to 'Schedule now', run_now_admin_job_path(resource), 'data-method' => :post, | |
:title => 'Cause a job scheduled in the future to run now.' | |
end | |
action_item :only => [:show, :edit] do | |
link_to 'Reset Job', reset_admin_job_path(resource), 'data-method' => :post, | |
:title => 'Resets the state caused by errors. Lets a worker give it another go ASAP.' | |
end | |
member_action :run_now, :method => :post do | |
resource.update_attributes run_at: Time.now | |
redirect_to action: :index | |
end | |
member_action :reset, :method => :post do | |
resource.update_attributes locked_at: nil, locked_by: nil, attempts: 0, last_error: nil | |
resource.update_attribute :attempts, 0 | |
redirect_to action: :index | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment