Skip to content

Commit 29dfcca

Browse files
committed
feat: Refactor ontologies report handling to use LinkedData::Jobs::OntologiesReportJob
1 parent 6415678 commit 29dfcca

4 files changed

Lines changed: 13 additions & 16 deletions

File tree

app.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
require_relative 'lib/rack/request_lang'
3131

3232
# sidekiq requirements
33-
require 'sidekiq/web'
3433
require 'sidekiq'
35-
34+
require 'sidekiq/web'
3635

3736
# Logging setup
3837
require_relative 'config/logging'

controllers/admin_controller.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class AdminController < ApplicationController
4141
end
4242

4343
get "/ontologies/:acronym/log" do
44-
ont_report = NcboCron::Models::OntologiesReport.new.ontologies_report(false)
44+
ont_report = LinkedData::Jobs::OntologiesReportJob.ontologies_report(false)
4545
log_path = ont_report[:ontologies].has_key?(params["acronym"].to_sym) ? "#{LinkedData.settings.repository_folder}/#{ont_report[:ontologies][params["acronym"].to_sym][:logFilePath]}" : ''
4646
log_contents = ''
4747

@@ -94,29 +94,27 @@ class AdminController < ApplicationController
9494

9595
get "/ontologies_report" do
9696
suppress_error = params["suppress_error"].eql?('true') # default = false
97-
reply NcboCron::Models::OntologiesReport.new.ontologies_report(suppress_error)
97+
reply LinkedData::Jobs::OntologiesReportJob.ontologies_report(suppress_error)
9898
end
9999

100100
post "/ontologies_report" do
101101
ontologies = ontologies_param_to_acronyms(params)
102-
args = {name: "ontologies_report", message: "refreshing ontologies report"}
103-
process_id = process_long_operation(900, args) do |args|
104-
NcboCron::Models::OntologiesReport.new.refresh_report(ontologies)
105-
end
102+
process_id = LinkedData::Jobs::OntologiesReportJob.perform_async({ "acronyms" => ontologies })
103+
redis.setex(process_id, 900, MultiJson.dump("processing"))
106104
reply(process_id: process_id)
107105
end
108106

109107
get "/ontologies_report/:process_id" do
110-
process_id = MultiJson.load(redis.get(params["process_id"]))
108+
status = MultiJson.load(redis.get(params["process_id"]))
111109

112-
if process_id.nil?
110+
if status.nil?
113111
error 404, "Process id #{params["process_id"]} does not exit"
114112
else
115-
if process_id === "done"
116-
reply NcboCron::Models::OntologiesReport.new.ontologies_report(false)
113+
if status === "done"
114+
reply LinkedData::Jobs::OntologiesReportJob.ontologies_report(false)
117115
else
118116
# either "processing" OR errors {errors: ["errorA", "errorB"]}
119-
reply process_id
117+
reply status
120118
end
121119
end
122120
end

controllers/ontologies_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class OntologiesController < ApplicationController
136136
error 422, "You must provide an existing `acronym` to delete" if ont.nil?
137137
ont.delete
138138
# update ontologies report file, if exists
139-
NcboCron::Models::OntologiesReport.new.delete_ontologies_from_report([params["acronym"]])
139+
LinkedData::Jobs::OntologiesReportJob.delete_ontologies_from_report([params["acronym"]])
140140
halt 204
141141
end
142142

@@ -232,7 +232,7 @@ def create_ontology
232232
latest_any = ont.latest_submission(status: :any)
233233

234234
if latest_any
235-
log_path = "#{LinkedData.settings.repository_folder}/#{NcboCron::Models::OntologiesReport.new.log_file(params["acronym"], latest_any.submissionId.to_s)}"
235+
log_path = "#{LinkedData.settings.repository_folder}/#{LinkedData::Jobs::OntologiesReportJob.log_file(params["acronym"], latest_any.submissionId.to_s)}"
236236

237237
if !log_path.empty? && File.file?(log_path)
238238
file = File.open(log_path, "rb")

jobs/submission_process_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def perform(options = {})
7676
multi_logger.error "Submission #{submission_id} parsing failed"
7777
end
7878

79-
NcboCron::Models::OntologiesReport.new(multi_logger).refresh_report([sub.ontology.acronym])
79+
LinkedData::Jobs::OntologiesReportJob.perform_async({ "acronyms" => [sub.ontology.acronym] })
8080

8181
clear_current_user
8282
end

0 commit comments

Comments
 (0)