Sha256: 002228e9da9a190546902c308bb44e2069e31731c1423b8f77ad5d203229bc0a

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module DelayedJobProgress
  class JobsController < ActionController::Base

    before_action :load_job, :only => [:show, :destroy, :reload]

    def index
      jobs = Delayed::Job
      if params[:record_type].present? && params[:record_id].present?
        jobs = jobs.where(:record_type => params[:record_type], :record_id => params[:record_id])
      end
      if params[:identifier].present?
        jobs = jobs.where(:identifier => params[:identifier])
      end

      render :json => jobs.all
    end

    def show
      render :json => @job
    end

    def destroy
      @job.destroy(:force)
      head :no_content
    end

    def reload
      @job.update_columns(
        :run_at       => Time.now,
        :failed_at    => nil,
        :completed_at => nil,
        :locked_by    => nil,
        :locked_at    => nil,
        :last_error   => nil,
        :attempts     => 0
      )
      render :json => @job
    end

  protected

    def load_job
      @job = Delayed::Job.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      render :json => {:error => 'Job not found'}, :status => :not_found
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
delayed_job_progress-0.0.1 app/controllers/delayed_job_progress/jobs_controller.rb