Class: Api::RefreshFeedJobStatesController

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

Overview

Controller to query the state of RefreshFeedWorker 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/refresh_feed_job_states_controller.rb', line 48

def destroy
  @job_state = current_user.find_refresh_feed_job_state params[:id]
  Rails.logger.debug "Destroying refresh_feed_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 “refresh feed” processes initiated by the current user


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

def index
  # If refresh feed job states have not changed, return a 304
  if stale? etag: EtagCalculator.etag(current_user.refresh_feed_jobs_updated_at),
            last_modified: current_user.refresh_feed_jobs_updated_at
    if RefreshFeedJobState.exists? user_id: current_user.id
      @job_states = RefreshFeedJobState.where user_id: current_user.id
      Rails.logger.debug "User #{current_user.id} - #{current_user.email} has #{@job_states.count} RefreshFeedJobState 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 “refresh feed” process initiated by the current user


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

def show
  @job_state = current_user.find_refresh_feed_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