Skip to content

Commit

Permalink
Fixed the job 404 exception error wurmlab#666 (wurmlab#710)
Browse files Browse the repository at this point in the history
* Fix Exception Handling and Implement Error Page
* Fixed the issues that arose from Code Climate
* Last Fix of routes.rb issues
  • Loading branch information
gorsyan authored Dec 21, 2023
1 parent a18f455 commit 22aa5e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/sequenceserver/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def serializable_classes
# Fetches job with the given id.
def fetch(id)
job_file = File.join(DOTDIR, id, 'job.yaml')
fail NotFound unless File.exist?(job_file)
return nil unless File.exist?(job_file)

YAML.safe_load_file(
job_file,
Expand Down
19 changes: 16 additions & 3 deletions lib/sequenceserver/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class Routes < Sinatra::Base
# an empty body if the job hasn't finished yet.
get '/:jid.json' do |jid|
job = Job.fetch(jid)
halt 404, { error: 'Job not found' }.to_json if job.nil?
halt 202 unless job.done?

report = Report.generate(job)
Expand Down Expand Up @@ -134,10 +135,12 @@ class Routes < Sinatra::Base

# Returns base HTML. Rest happens client-side: polling for and rendering
# the results.
get '/:jid' do
get '/:jid' do |jid|
job = Job.fetch(jid)
raise NotFound, 'Job not found' if job.nil?

erb :report, layout: true
end

# @params sequence_ids: whitespace separated list of sequence ids to
# retrieve
# @params database_ids: whitespace separated list of database ids to
Expand Down Expand Up @@ -167,14 +170,17 @@ class Routes < Sinatra::Base
# Download BLAST report in various formats.
get '/download/:jid.:type' do |jid, type|
job = Job.fetch(jid)
halt 404, { error: 'Job not found' }.to_json if job.nil?
out = BLAST::Formatter.new(job, type)
halt 404, { error: 'File not found"' }.to_json unless File.exist?(out.filepath)
send_file out.filepath, filename: out.filename, type: out.mime
end

post '/cloud_share' do
content_type :json
request_params = JSON.parse(request.body.read)
job = Job.fetch(request_params['job_id'])
halt 404, { error: 'Job not found' }.to_json if job.nil?

unless job.done?
status 422
Expand Down Expand Up @@ -279,7 +285,8 @@ class Routes < Sinatra::Base

# Get the query sequences, selected databases, and advanced params used.
def update_searchdata_from_job(searchdata)
job = Job.fetch(params[:job_id])
job = fetch_job(params[:job_id])
return { error: 'Job not found' }.to_json if job.nil?
return if job.imported_xml_file

# Only read job.qfile if we are not going to use Database.retrieve.
Expand All @@ -301,5 +308,11 @@ def update_searchdata_from_job(searchdata)
searchdata[:options][method]['last search'] = [job.advanced]
end
end

private

def fetch_job(job_id)
Job.fetch(job_id)
end
end
end

0 comments on commit 22aa5e9

Please sign in to comment.