Class: Api::SubscribeJobStatesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/api/subscribe_job_states_controller.rb

Overview

Controller to query the state of SubscribeUserWorker instances enqued for the user.

Instance Method Summary collapse

Instance Method Details

#destroyObject

Remove job state from the database. This will make its alert disappear from the start page as well.


48
49
50
51
52
53
54
55
# File 'app/controllers/api/subscribe_job_states_controller.rb', line 48

def destroy
  @job_state = current_user.find_subscribe_job_state params[:id]
  Rails.logger.debug "Destroying subscribe_job_state #{@job_state.id} for user #{current_user.id} - #{current_user.email}"
  @job_state.destroy!
  head 200
rescue => e
  handle_error e
end

#indexObject

Return JSON indicating the state of the subscribe jobs initiated by the current user


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/api/subscribe_job_states_controller.rb', line 15

def index
  # If subscribe job states have not changed, return a 304
  if stale? etag: EtagCalculator.etag(current_user.subscribe_jobs_updated_at),
            last_modified: current_user.subscribe_jobs_updated_at
    if SubscribeJobState.exists? user_id: current_user.id
      @job_states = SubscribeJobState.where user_id: current_user.id
      Rails.logger.debug "User #{current_user.id} - #{current_user.email} has #{@job_states.count} SubscribeJobState instances"
      respond_with @job_states
    else
      head 404
    end
  end
rescue => e
  handle_error e
end

#showObject

Return JSON indicating the state of a single subscribe job initiated by the current user


34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/api/subscribe_job_states_controller.rb', line 34

def show
  @job_state = current_user.find_subscribe_job_state params[:id]
  # If job state has not changed, return a 304
  if stale? etag: EtagCalculator.etag(@job_state.updated_at),
            last_modified: @job_state.updated_at
    respond_with @job_state
  end
rescue => e
  handle_error e
end