Class: Qujo::JobsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Qujo::JobsController
- Defined in:
- app/controllers/qujo/jobs_controller.rb
Instance Method Summary collapse
- #accept ⇒ Object
-
#all ⇒ Object
GET /jobs/all GET /jobs/all.json.
-
#create ⇒ Object
POST /jobs POST /jobs.json.
-
#destroy ⇒ Object
DELETE /jobs/1 DELETE /jobs/1.json.
-
#errors ⇒ Object
GET /jobs/errors GET /jobs/errors.json.
-
#index ⇒ Object
GET /jobs GET /jobs.json.
-
#new ⇒ Object
GET /jobs/new GET /jobs/new.json.
-
#refresh ⇒ Object
PUT /jobs/1 PUT /jobs/1.json def update @job = Job.find(params).
- #resque ⇒ Object
-
#show ⇒ Object
GET /jobs/1 GET /jobs/1.json.
- #status ⇒ Object
Instance Method Details
#accept ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/controllers/qujo/jobs_controller.rb', line 150 def accept id = params[:id] if id == "all" Job.where(accepted_at: nil).update_all(accepted_at: Time.now) else @job = Job.find(id) @job.accept end head :no_content rescue => e render json: {message: e.} end |
#all ⇒ Object
GET /jobs/all GET /jobs/all.json
53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/qujo/jobs_controller.rb', line 53 def all #@jobs = Job.all q = Job.scoped q = q.unscoped @jobs = q.desc(:created_at).limit(50).all respond_to do |format| format.html { render "index"} # index.html.erb format.json { render json: @jobs } end end |
#create ⇒ Object
POST /jobs POST /jobs.json
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/qujo/jobs_controller.rb', line 97 def create p = params[:job] logger.info "JOB CREATE: #{p.inspect}" k = Job if p["_type"] t = p.delete("_type") begin k = t.constantize rescue => e logger.info "TYPE:#{k} failed" end end logger.info "JOB CREATE: #{p.inspect}" @job = k.new(p) respond_to do |format| if @job.save @job.enqueue format.html { redirect_to @job, notice: 'Job was successfully created.' } format.json { render json: @job, status: :created, location: @job } else format.html { render action: "new" } format.json { render json: @job.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /jobs/1 DELETE /jobs/1.json
166 167 168 169 170 171 172 173 174 |
# File 'app/controllers/qujo/jobs_controller.rb', line 166 def destroy @job = Job.unscoped.find(params[:id]) @job.cancel respond_to do |format| format.html { redirect_to jobs_url } format.json { head :no_content } end end |
#errors ⇒ Object
GET /jobs/errors GET /jobs/errors.json
40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/qujo/jobs_controller.rb', line 40 def errors #@jobs = Job.all q = Job.scoped @jobs = q.errors.desc(:created_at).all respond_to do |format| format.html { render "index"} # index.html.erb format.json { render json: @jobs } end end |
#index ⇒ Object
GET /jobs GET /jobs.json
4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/controllers/qujo/jobs_controller.rb', line 4 def index #@jobs = Job.all q = Job.scoped q = q.unscoped @jobs = q.desc(:created_at).limit(25).all respond_to do |format| format.html # index.html.erb format.json { render json: @jobs } end end |
#new ⇒ Object
GET /jobs/new GET /jobs/new.json
81 82 83 84 85 86 87 88 |
# File 'app/controllers/qujo/jobs_controller.rb', line 81 def new @job = Job.new respond_to do |format| format.html # new.html.erb format.json { render json: @job } end end |
#refresh ⇒ Object
PUT /jobs/1 PUT /jobs/1.json def update
@job = Job.find(params[:id])
respond_to do |format|
if @job.update_attributes(params[:job])
format.html { redirect_to @job, notice: 'Job was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end
140 141 142 143 144 145 146 147 148 |
# File 'app/controllers/qujo/jobs_controller.rb', line 140 def refresh @job = Job.unscoped.find(params[:id]) @job.retry @job.enqueue head :no_content rescue => e render json: {message: e.} end |
#resque ⇒ Object
16 17 18 |
# File 'app/controllers/qujo/jobs_controller.rb', line 16 def resque end |
#show ⇒ Object
GET /jobs/1 GET /jobs/1.json
67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/controllers/qujo/jobs_controller.rb', line 67 def show @job = Job.unscoped.find(params[:id]) # sometimes things don't get updated (can't see trace on errors) # if identity map is enabled @job = @job.reload respond_to do |format| format.html # show.html.erb format.json { render json: @job } end end |
#status ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/qujo/jobs_controller.rb', line 20 def status job_count = Job.count job_error = Job.errors? resque_count = Resque.workers.count resque_error = (resque_count == 0 || Resque::Failure.count > 0) d = { jobs: { count: job_count, error: job_error }, resque: { count: resque_count, error: resque_error, } } render json: d, status: :ok end |