Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spike 5000 queries round deux #1039

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ GEM
cmdstan (0.3.1)
csv
colorize (1.1.0)
concurrent-ruby (1.3.1)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
cookies_eu (1.7.8)
js_cookie_rails (~> 2.2.0)
Expand Down Expand Up @@ -226,6 +226,7 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
local_time (3.0.2)
logger (1.6.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -435,11 +436,12 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sidekiq (7.2.4)
sidekiq (7.3.0)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
logger
rack (>= 2.2.4)
redis-client (>= 0.19.0)
redis-client (>= 0.22.2)
sidekiq-limit_fetch (4.4.1)
sidekiq (>= 6)
simplecov (0.22.0)
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/components/export_case/_modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ <h3 class="modal-title">Export Case: <span class="modal-case">{{ ctrl.theCase.ca
Detailed export is only supported from the individual Case view.
</p>
<span class="help-block">
CSV file with <code>Team Name,Case Name,Case ID,Query Text,Doc ID,Title,Rating,Field1,...,FieldN</code> where <code>Field1,...,FieldN</code> are specified under <strong>Settings</strong> in the <strong>Displayed Fields</strong> field.
CSV file with <code>Team Name,Case Name,Case ID,Query Text,Doc ID,Position,Title,Rating,Field1,...,FieldN</code> where <code>Field1,...,FieldN</code> are specified under <strong>Settings</strong> in the <strong>Displayed Fields</strong> field.
</span>
</div>

Expand Down
4 changes: 3 additions & 1 deletion app/assets/javascripts/services/caseCSVSvc.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
'Case ID',
'Query Text',
'Doc ID',
'Doc Position',
'Title',
'Rating',
];
Expand Down Expand Up @@ -353,7 +354,7 @@
csvContent += dataString + EOL;
}
else {
angular.forEach(docs, function (doc) {
angular.forEach(docs, function (doc, index) {
var dataString;
var infoArray = [];

Expand All @@ -362,6 +363,7 @@
infoArray.push(stringifyField(aCase.lastScore.case_id));
infoArray.push(stringifyField(query.queryText));
infoArray.push(stringifyField(doc.id));
infoArray.push(stringifyField(index+1));
infoArray.push(stringifyField(doc.title));
infoArray.push(stringifyField(doc.getRating()));

Expand Down
18 changes: 18 additions & 0 deletions app/controllers/admin/query_runner_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module Admin
class QueryRunnerController < ApplicationController
before_action :set_case, only: [ :run_queries ]

def index
end

def run_queries
@case = Case.find(params['case_id']) # any case is accessible!
@try = @case.tries.where(try_number: params['try_number']).first
QueryRunnerJob.perform_later @case, @try
redirect_to admin_query_runner_index_path,
notice: "Query Runner Job was queued up for case #{@case.case_name} and try #{@try.name}."
end
end
end
66 changes: 66 additions & 0 deletions app/jobs/query_runner_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true

require 'action_controller'
require 'faraday'
require 'faraday/follow_redirects'

class QueryRunnerJob < ApplicationJob
queue_as :bulk_processing

# rubocop:disable Metrics/MethodLength
def perform acase, atry
query_count = acase.queries.count

options = {
fake_mode: true,
debug_mode: true,
snapshot_limit: 3,
}

fetch_service = FetchService.new options
fetch_service.begin(acase, atry)

acase.queries.each_with_index do |query, counter|
response = fetch_service.make_request(atry, query)

response_code = response.status
response_body = response.body

docs = []
fetch_service.store_query_results query, docs, response_code, response_body

Turbo::StreamsChannel.broadcast_render_to(
:notifications,
target: 'notifications',
partial: 'admin/query_runner/notification',
locals: { query: query, query_count: query_count, counter: counter }
)

Turbo::StreamsChannel.broadcast_render_to(
:notifications,
target: "notifications-case-#{acase.id}",
partial: 'admin/query_runner/notification_case',
locals: { acase: acase, query: query, query_count: query_count, counter: counter }
)

sleep(2)
end

Turbo::StreamsChannel.broadcast_render_to(
:notifications,
target: 'notifications',
partial: 'admin/query_runner/notification',
locals: { query: nil, query_count: query_count, counter: 0 }
)

Turbo::StreamsChannel.broadcast_render_to(
:notifications,
target: "notifications-case-#{acase.id}",
partial: 'admin/query_runner/notification_case',
locals: { acase: acase, query: nil, query_count: query_count, counter: 0 }
)

fetch_service.complete
end
# rubocop:enable Metrics/MethodLength
end
4 changes: 2 additions & 2 deletions app/models/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class Snapshot < ApplicationRecord
# rubocop:disable Rails/HasManyOrHasOneDependent
has_many :snapshot_queries
# rubocop:enable Rails/HasManyOrHasOneDependent
has_many :snapshot_docs,
through: :snapshot_queries
has_many :snapshot_docs,
through: :snapshot_queries

has_one_attached :snapshot_file

Expand Down
2 changes: 2 additions & 0 deletions app/models/snapshot_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# id :integer not null, primary key
# all_rated :boolean
# number_of_results :integer
# response_body :text(65535)
# response_status :integer
# score :float(24)
# query_id :integer
# snapshot_id :integer
Expand Down
Loading