Class: JobsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/jobs_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin!, #authenticate_user!, #forbidden_response, #json_request?, #record_not_found, #unauthorized_response

Instance Method Details

#destroyObject


36
37
38
39
40
# File 'app/controllers/jobs_controller.rb', line 36

def destroy
  @job ||= Delayed::Web::Job.find params[:id]
  @job.destroy
  redirect_to :back, notice: 'Job was successfully destroyed!'
end

#indexObject


4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/jobs_controller.rb', line 4

def index
  respond_to do |format|
    format.html{
      @jobs ||= Delayed::Web::Job.all
    }

    format.json{
      @jobs = JobWrapper.all
      render json: @jobs, status: :ok
    }
  end
end

#runObject


42
43
44
45
46
47
48
49
50
# File 'app/controllers/jobs_controller.rb', line 42

def run
  @job ||= Delayed::Web::Job.find params[:job_id]
  if @job.can_queue?
    @job.queue!
    redirect_to jobs_path, notice: 'Job has been queued for running.'
  else
    redirect_to jobs_path, notice: 'Job could not be queued.'
  end
end

#showObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/jobs_controller.rb', line 17

def show
  respond_to do |format|
    format.html {
      @job ||= Delayed::Web::Job.find params[:id]
    }

    format.json {
      @job = JobWrapper.find_by_uuid(params[:id])
      if @job.nil?
        render json:'There is no job with the given ID!', status: :not_found
      else
        render json: @job, status: :ok
      end
    }
  end

  @job ||= Delayed::Web::Job.find params[:id]
end