Class: JobsController

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

Instance Method Summary collapse

Instance Method Details

#indexObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/jobs_controller.rb', line 2

def index

	trys = 0
	while(trys < 30)
		SpudPrinter.uncached do
			@printers = SpudPrinter.where(:access_token => params[:keys]).includes(:active_jobs).all
			job_count = 0
			puts "printer query each method"
			@printers.each do |printer|
				puts("Checking job count on printer")
				job_count = 0
				printer.active_jobs.all.each do |job|
					if File.exist?(File.join(Rails.root,'public','report_jobs',job.attachment_file_name))
						job_count += 1
					else
						job.update_attributes(:status => 1)
					end
				end
				puts(job_count)
			end
			if job_count > 0
				render and return
			end
			sleep 1
			trys += 1
		end
	end
end

#showObject



31
32
33
34
35
36
37
38
# File 'app/controllers/jobs_controller.rb', line 31

def show
	@job = SpudPrintJob.find(params[:id])
	if !@job.blank?
		@job.update_attributes(:status => 1)
		File.delete(File.join(Rails.root,'public','report_jobs',@job.attachment_file_name))
	end
	render :status => 200,:text => nil
end

#updateObject



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

def update
	@job = SpudPrintJob.find(params[:id])
	if @job
		if @job.spud_printer.key == params[:key]
			@job.status = 1
			#TODO DELETE ATTACHMENT_FILE
			@job.save
			render :text => nil,:status => 200 and return
		end
	end
	render :text => nil,:status => 500
end