Class: Profiler::Api::JobsController

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

Instance Method Summary collapse

Instance Method Details

#clearObject



33
34
35
36
# File 'app/controllers/profiler/api/jobs_controller.rb', line 33

def clear
  Profiler.storage.clear(type: "job")
  head :no_content
end

#destroyObject



25
26
27
28
29
30
31
# File 'app/controllers/profiler/api/jobs_controller.rb', line 25

def destroy
  profile = Profiler.storage.load(params[:id])
  return render json: { error: "Job profile not found" }, status: :not_found unless profile&.profile_type == "job"

  Profiler.storage.delete(params[:id])
  head :no_content
end

#indexObject



8
9
10
11
12
13
# File 'app/controllers/profiler/api/jobs_controller.rb', line 8

def index
  all_profiles = Profiler.storage.list(limit: (params[:limit] || 200).to_i, offset: (params[:offset] || 0).to_i)
  job_profiles = all_profiles.select { |p| p.profile_type == "job" }
  job_profiles = job_profiles.first((params[:limit] || 50).to_i)
  render json: job_profiles.map(&:to_h)
end

#showObject



15
16
17
18
19
20
21
22
23
# File 'app/controllers/profiler/api/jobs_controller.rb', line 15

def show
  profile = Profiler.storage.load(params[:id])

  unless profile && profile.profile_type == "job"
    return render json: { error: "Job profile not found" }, status: :not_found
  end

  render json: profile.to_h
end