Skip to content

Instantly share code, notes, and snippets.

@webmat
Created February 22, 2012 20:46
Show Gist options
  • Save webmat/1887148 to your computer and use it in GitHub Desktop.
Save webmat/1887148 to your computer and use it in GitHub Desktop.

Revisions

  1. webmat revised this gist Jun 29, 2012. 1 changed file with 7 additions and 8 deletions.
    15 changes: 7 additions & 8 deletions jobs.rb
    Original file line number Diff line number Diff line change
    @@ -41,29 +41,28 @@
    end

    action_item :only => [:edit] do
    link_to 'Delete Job', admin_job_path(@job), 'data-method' => :delete, 'data-confirm' => 'Are you sure?'
    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(@job), 'data-method' => :post,
    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(@job), 'data-method' => :post,
    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
    job = Delayed::Job.find(params[:id])
    job.update_attributes run_at: Time.now
    resource.update_attributes run_at: Time.now
    redirect_to action: :index
    end

    member_action :reset, :method => :post do
    job = Delayed::Job.find(params[:id])
    job.update_attributes locked_at: nil, locked_by: nil, attempts: 0, last_error: nil
    job.update_attribute :attempts, 0
    resource.update_attributes locked_at: nil, locked_by: nil, attempts: 0, last_error: nil
    resource.update_attribute :attempts, 0
    redirect_to action: :index
    end

  2. webmat revised this gist Apr 3, 2012. 1 changed file with 25 additions and 9 deletions.
    34 changes: 25 additions & 9 deletions jobs.rb
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    ActiveAdmin.register Delayed::Job, as: 'Job' do
    menu parent: 'Admin'

    actions :index, :show, :edit, :destroy
    actions :index, :show, :edit, :update, :destroy

    index do
    column :id
    column :queue
    column :priority
    column :attempts
    column :created_at
    column :failed_at
    column :run_at
    column :created_at
    column :locked_by
    column :locked_at
    default_actions
    @@ -29,7 +31,7 @@
    end

    f.inputs "Diagnostics" do
    f.input :attempts
    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}
    @@ -38,17 +40,31 @@
    f.buttons
    end

    action_item :only => [:edit] do
    link_to 'Delete Job', admin_job_path(@job), 'data-method' => :delete, 'data-confirm' => 'Are you sure?'
    end

    action_item :only => [:show, :edit] do
    link_to 'Schedule now', run_now_admin_job_path(@job), '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(@job), '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
    job = Delayed::Job.find(params[:id])
    job.update_attributes run_at: Time.now
    redirect_to action: :index
    end

    action_item :only => [:show, :edit] do
    link_to 'Delete', admin_job_path(@job), 'data-method' => :delete, 'data-confirm' => 'Are you sure?'
    member_action :reset, :method => :post do
    job = Delayed::Job.find(params[:id])
    job.update_attributes locked_at: nil, locked_by: nil, attempts: 0, last_error: nil
    job.update_attribute :attempts, 0
    redirect_to action: :index
    end

    action_item :only => [:show, :edit] do
    link_to 'Schedule now', run_now_admin_job_path(@job), 'data-method' => :post
    end
    end
    end
  3. webmat revised this gist Mar 1, 2012. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions jobs.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    ActiveAdmin.register Delayed::Job, as: 'Job' do
    menu parent: 'Admin'

    actions :index, :show, :edit, :delete
    actions :index, :show, :edit, :destroy

    index do
    column :id
    @@ -44,7 +44,11 @@
    redirect_to action: :index
    end

    sidebar "Perform", only: [:show, :edit] do
    a 'Schedule for now!', href: run_now_admin_job_path, 'data-method' => :post
    action_item :only => [:show, :edit] do
    link_to 'Delete', admin_job_path(@job), 'data-method' => :delete, 'data-confirm' => 'Are you sure?'
    end

    action_item :only => [:show, :edit] do
    link_to 'Schedule now', run_now_admin_job_path(@job), 'data-method' => :post
    end
    end
  4. webmat revised this gist Feb 23, 2012. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions dashboards.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    ActiveAdmin::Dashboards.build do
    # Add this section in your dashboard...

    section "Background Jobs" do
    now = Time.now.getgm
    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
  5. webmat revised this gist Feb 23, 2012. 1 changed file with 3 additions and 4 deletions.
    7 changes: 3 additions & 4 deletions jobs.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ActiveAdmin.register Delayed::Job do
    ActiveAdmin.register Delayed::Job, as: 'Job' do
    menu parent: 'Admin'

    actions :index, :show, :edit, :delete
    @@ -45,7 +45,6 @@
    end

    sidebar "Perform", only: [:show, :edit] do
    # aa creates extremely weird routes for the DJ model atm
    a 'Schedule for now!', href: "#{request.path}/run_now", 'data-method' => :post
    a 'Schedule for now!', href: run_now_admin_job_path, 'data-method' => :post
    end
    end
    end
  6. webmat revised this gist Feb 22, 2012. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions jobs.rb
    Original file line number Diff line number Diff line change
    @@ -37,4 +37,15 @@
    end
    f.buttons
    end

    member_action :run_now, :method => :post do
    job = Delayed::Job.find(params[:id])
    job.update_attributes run_at: Time.now
    redirect_to action: :index
    end

    sidebar "Perform", only: [:show, :edit] do
    # aa creates extremely weird routes for the DJ model atm
    a 'Schedule for now!', href: "#{request.path}/run_now", 'data-method' => :post
    end
    end
  7. webmat revised this gist Feb 22, 2012. No changes.
  8. webmat created this gist Feb 22, 2012.
    40 changes: 40 additions & 0 deletions jobs.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    ActiveAdmin.register Delayed::Job do
    menu parent: 'Admin'

    actions :index, :show, :edit, :delete

    index do
    column :id
    column :priority
    column :attempts
    column :created_at
    column :run_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
    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
    end