From 107f861705f2920024ceb78412cbd0d1e7d042e7 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Fri, 8 Mar 2024 09:22:58 -0500
Subject: [PATCH 01/19] boom! Wrapped the Angular1 app into a end point that
can be called by anyone.
---
Gemfile | 2 +
Gemfile.lock | 6 +
app/assets/javascripts/app_stripped.js | 13 ++
.../javascripts/controllers/mainCtrl.js | 30 ++--
.../controllers/queriesStrippedCtrl.js | 62 +++++++
.../javascripts/controllers/queryParams.js | 1 +
.../javascripts/controllers/strippedCtrl.js | 169 ++++++++++++++++++
app/assets/javascripts/core.js | 1 -
app/assets/javascripts/core_stripped.js | 41 +++++
.../javascripts/directives/queriesStripped.js | 14 ++
.../javascripts/factories/TryFactory.js | 1 +
app/assets/javascripts/routes.js | 5 +
app/assets/javascripts/services/queriesSvc.js | 4 +
.../javascripts/services/querySnapshotSvc.js | 22 ++-
.../templates/views/devQueryParams.html | 30 +++-
.../templates/views/queries-stripped.html | 22 +++
.../templates/views/queriesStripped.html | 28 +++
app/controllers/api/v1/agent_q_controller.rb | 87 +++++++++
app/controllers/api/v1/queries_controller.rb | 6 +-
app/controllers/core_controller.rb | 13 ++
app/controllers/core_stripped_controller.rb | 36 ++++
app/views/core_stripped/index.html.erb | 17 ++
app/views/layouts/core_stripped.html.erb | 35 ++++
config/initializers/assets.rb | 4 +-
config/routes.rb | 5 +
25 files changed, 632 insertions(+), 22 deletions(-)
create mode 100644 app/assets/javascripts/app_stripped.js
create mode 100644 app/assets/javascripts/controllers/queriesStrippedCtrl.js
create mode 100644 app/assets/javascripts/controllers/strippedCtrl.js
create mode 100644 app/assets/javascripts/core_stripped.js
create mode 100644 app/assets/javascripts/directives/queriesStripped.js
create mode 100644 app/assets/templates/views/queries-stripped.html
create mode 100644 app/assets/templates/views/queriesStripped.html
create mode 100644 app/controllers/api/v1/agent_q_controller.rb
create mode 100755 app/controllers/core_stripped_controller.rb
create mode 100755 app/views/core_stripped/index.html.erb
create mode 100755 app/views/layouts/core_stripped.html.erb
diff --git a/Gemfile b/Gemfile
index 28b89130d..71d5529e9 100755
--- a/Gemfile
+++ b/Gemfile
@@ -91,3 +91,5 @@ group :test do
end
gem 'importmap-rails', '~> 2.0'
+
+gem "ferrum", "~> 0.15"
diff --git a/Gemfile.lock b/Gemfile.lock
index 84be5ac2f..8375582ab 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -168,6 +168,11 @@ GEM
faraday (>= 1, < 3)
faraday-net_http (3.1.0)
net-http
+ ferrum (0.15)
+ addressable (~> 2.5)
+ concurrent-ruby (~> 1.1)
+ webrick (~> 1.7)
+ websocket-driver (~> 0.7)
ffi (1.16.3)
font-awesome-sass (6.5.1)
sassc (~> 2.0)
@@ -508,6 +513,7 @@ DEPENDENCIES
derailed_benchmarks
devise (>= 4.6.2)
devise_invitable (~> 2.0)
+ ferrum (~> 0.15)
font-awesome-sass
gabba
importmap-rails (~> 2.0)
diff --git a/app/assets/javascripts/app_stripped.js b/app/assets/javascripts/app_stripped.js
new file mode 100644
index 000000000..07979c1fb
--- /dev/null
+++ b/app/assets/javascripts/app_stripped.js
@@ -0,0 +1,13 @@
+'use strict';
+
+angular.module('QuepidApp', [
+ 'UtilitiesModule',
+ 'ngRoute',
+ 'ngCookies',
+ 'ngSanitize',
+ 'ui.bootstrap',
+ 'o19s.splainer-search',
+ 'angular-flash.service',
+ 'angular-flash.flash-alert-directive',
+ 'templates'
+]);
diff --git a/app/assets/javascripts/controllers/mainCtrl.js b/app/assets/javascripts/controllers/mainCtrl.js
index 85c16c2ca..3b856b4da 100644
--- a/app/assets/javascripts/controllers/mainCtrl.js
+++ b/app/assets/javascripts/controllers/mainCtrl.js
@@ -106,15 +106,25 @@ angular.module('QuepidApp')
flash.to('search-error').error = '';
bootstrapped = true;
- return queriesSvc.searchAll()
- .then(function() {
- flash.success = 'All queries finished successfully!';
- }, function(errorMsg) {
- var mainErrorMsg = 'Some queries failed to resolve!';
-
- flash.error = mainErrorMsg;
- flash.to('search-error').error = errorMsg;
- });
+
+ console.log(queriesSvc.queryArray().length)
+ if (queriesSvc.queryArray().length <= 410) {
+ console.log("About to call queriesSvc.searchAll")
+ return queriesSvc.searchAll()
+ .then(function() {
+ flash.success = 'All queries finished successfully!';
+ }, function(errorMsg) {
+ var mainErrorMsg = 'Some queries failed to resolve!';
+
+ flash.error = mainErrorMsg;
+ flash.to('search-error').error = errorMsg;
+ });
+ }
+ else {
+ queriesSvc.requireManualTrigger = true;
+ flash.success = 'You have ' + queriesSvc.queryArray().length + ' queries in this case and must manually trigger running this!';
+ return
+ }
}
});
});
@@ -143,7 +153,7 @@ angular.module('QuepidApp')
}
else if ( caseNo > 0 ) {
queriesSvc.querySearchPromiseReset();
-
+ console.log("about to bootstrapCase")
bootstrapCase()
.then(function() {
loadQueries();
diff --git a/app/assets/javascripts/controllers/queriesStrippedCtrl.js b/app/assets/javascripts/controllers/queriesStrippedCtrl.js
new file mode 100644
index 000000000..ab8a2f6ee
--- /dev/null
+++ b/app/assets/javascripts/controllers/queriesStrippedCtrl.js
@@ -0,0 +1,62 @@
+'use strict';
+/*jslint latedef:false*/
+
+angular.module('QuepidApp')
+ .controller('QueriesStrippedCtrl', [
+ '$scope',
+ 'queriesSvc',
+ 'querySnapshotSvc',
+ 'caseSvc',
+ function (
+ $scope,
+ queriesSvc,
+ querySnapshotSvc,
+ caseSvc
+ ) {
+ $scope.queriesSvc = queriesSvc;
+ $scope.caseSvc = caseSvc;
+
+ console.log("HI THERE")
+
+ $scope.queries = {};
+
+ $scope.queries.queriesChanged = function() {
+ return queriesSvc.version();
+ };
+
+
+ // get all the queries for this case for the query service
+ $scope.queriesList = [];
+ $scope.$watch(function(){
+ // only call if the query service has new information!
+ return queriesSvc.version();
+ }, function(){
+ $scope.queriesList = queriesSvc.queryArray();
+ updateBatchInfo();
+ });
+
+ $scope.snapshotPayload = function() {
+ if (!$scope.searching()){
+ return querySnapshotSvc.createSnapshotPayload("", true, false, queriesSvc.queryArray());
+ }
+ }
+
+ $scope.searching = function() {
+ return queriesSvc.hasUnscoredQueries();
+ };
+ $scope.batchPosition = 0;
+ $scope.batchSize = 0;
+ function getBatchPosition() {
+ return queriesSvc.scoredQueryCount();
+ }
+
+ function updateBatchInfo() {
+ $scope.batchSize = queriesSvc.queryCount();
+ $scope.batchPosition = queriesSvc.scoredQueryCount();
+ }
+ $scope.$watch(getBatchPosition, updateBatchInfo);
+
+
+
+ }
+ ]);
diff --git a/app/assets/javascripts/controllers/queryParams.js b/app/assets/javascripts/controllers/queryParams.js
index 0764f3c51..c207ea17f 100644
--- a/app/assets/javascripts/controllers/queryParams.js
+++ b/app/assets/javascripts/controllers/queryParams.js
@@ -102,6 +102,7 @@ angular.module('QuepidApp')
args: $scope.settings.selectedTry.args,
curator_vars: $scope.settings.selectedTry.curatorVarsDict(),
escape_query: $scope.settings.selectedTry.escapeQuery,
+ background_queries: $scope.settings.selectedTry.backgroundQueries,
api_method: $scope.settings.selectedTry.apiMethod,
custom_headers: $scope.settings.selectedTry.customHeaders,
field_spec: $scope.settings.selectedTry.fieldSpec,
diff --git a/app/assets/javascripts/controllers/strippedCtrl.js b/app/assets/javascripts/controllers/strippedCtrl.js
new file mode 100644
index 000000000..e0a2e0d63
--- /dev/null
+++ b/app/assets/javascripts/controllers/strippedCtrl.js
@@ -0,0 +1,169 @@
+'use strict';
+
+angular.module('QuepidApp')
+ // there's a lot of dependencies here, but this guy
+ // is responsible for bootstrapping everyone so...
+ .controller('StrippedCtrl', [
+ '$scope', '$routeParams', '$log',
+ 'flash',
+ 'caseSvc', 'settingsSvc', 'caseTryNavSvc',
+ 'queryViewSvc', 'queriesSvc', 'docCacheSvc',
+ function (
+ $scope, $routeParams, $log,
+ flash,
+ caseSvc, settingsSvc, caseTryNavSvc,
+ queryViewSvc, queriesSvc, docCacheSvc
+ ) {
+ $log.debug('NEW MAIN CTRL STRIPPED VERSION');
+
+ var caseNo = parseInt($routeParams.caseNo, 10);
+ var tryNo = parseInt($routeParams.tryNo, 10);
+
+ var initialCaseNo = angular.copy(caseTryNavSvc.getCaseNo());
+
+ var caseChanged = function() {
+ return initialCaseNo !== caseNo;
+ };
+
+ var getSearchEngine = function(tryNo) {
+ var settings = settingsSvc.editableSettings();
+ if (settings.hasOwnProperty('getTry')) {
+ var aTry = settings.getTry(tryNo);
+ if (aTry) {
+ return aTry.searchUrl;
+ }
+ }
+ return null;
+ };
+
+ var searchEngineChanged = function() {
+ return getSearchEngine(caseTryNavSvc.getTryNo()) !== getSearchEngine(tryNo);
+ };
+
+ var init = function() {
+ // Make sure we empty stuff from the previous case
+ if ( caseChanged() ) {
+ queriesSvc.reset();
+ }
+
+ angular.forEach(queriesSvc.queries, function(query) {
+ query.reset();
+ });
+ };
+
+ var bootstrapCase = function() {
+ return caseSvc.get(caseNo)
+ .then(function(acase) {
+ if (angular.isUndefined(acase)){
+ throw new Error('Could not retrieve case ' + caseNo + '. Confirm that the case has been shared with you via a team you are a member of!');
+ }
+
+ caseSvc.selectTheCase(acase);
+ settingsSvc.setCaseTries(acase.tries);
+ if ( isNaN(tryNo) ) { // If we didn't specify a tryNo via the URL
+ tryNo = acase.lastTry;
+ }
+
+ settingsSvc.setCurrentTry(tryNo);
+ if (!settingsSvc.isTrySelected()){
+ flash.to('search-error').error = 'The try that was specified for the case does not actually exist!';
+ }
+ else {
+ if (settingsSvc.editableSettings().proxyRequests === true){
+ $scope.showTLSChangeWarning = false;
+ }
+ else if (caseTryNavSvc.needToRedirectQuepidProtocol(settingsSvc.editableSettings().searchUrl)){
+ $log.info('Need to redirect browser to different TLS');
+ throw new Error('Need to change to different TLS'); // Signal that we need to change TLS.
+ }
+ }
+ });
+ };
+
+ var loadQueries = function() {
+ var newSettings = settingsSvc.editableSettings();
+ if ( caseChanged() || searchEngineChanged() ) {
+ if ( caseChanged() ) {
+ queryViewSvc.reset();
+ docCacheSvc.empty();
+ }
+ docCacheSvc.invalidate();
+ }
+
+ return docCacheSvc.update(newSettings)
+ .then(function() {
+ var bootstrapped = false;
+
+ return queriesSvc.changeSettings(caseNo, newSettings)
+ .then(function() {
+ if (!bootstrapped) {
+ flash.error = '';
+ flash.success = '';
+ flash.to('search-error').error = '';
+
+ bootstrapped = true;
+
+ console.log(queriesSvc.queryArray().length)
+ if (queriesSvc.queryArray().length <= 410) {
+ console.log("About to call queriesSvc.searchAll")
+ return queriesSvc.searchAll()
+ .then(function() {
+ flash.success = 'All queries finished successfully!';
+ }, function(errorMsg) {
+ var mainErrorMsg = 'Some queries failed to resolve!';
+
+ flash.error = mainErrorMsg;
+ flash.to('search-error').error = errorMsg;
+ });
+ }
+ else {
+ queriesSvc.requireManualTrigger = true;
+ flash.success = 'You have ' + queriesSvc.queryArray().length + ' queries in this case and must manually trigger running this!';
+ return
+ }
+ }
+ });
+ });
+ };
+
+ init();
+
+ caseTryNavSvc.navigationCompleted({
+ caseNo: caseNo,
+ tryNo: tryNo
+ });
+
+ // While not perfect, at least the site doesn't blow up if you don't
+ // have any cases.
+ if ( caseNo === 0 ) {
+ flash.error = 'You don\'t have any Cases created in Quepid. Click \'Create a Case\' from the Relevancy Cases dropdown to get started.';
+ }
+ else if ( caseNo > 0 ) {
+ queriesSvc.querySearchPromiseReset();
+ console.log("about to bootstrapCase")
+ bootstrapCase()
+ .then(function() {
+ loadQueries();
+ }).catch(function(error) {
+ // brittle logic, but check if we throw the TLS error or if it's from something else.'
+ var message = error.message;
+ if (message === 'Need to change to different TLS'){
+ var resultsTuple = caseTryNavSvc.swapQuepidUrlTLS();
+
+ var quepidUrlToSwitchTo = resultsTuple[0];
+ var protocolToSwitchTo = resultsTuple[1];
+
+ flash.to('search-error').error = 'Click Here to Reload Quepid in ' + protocolToSwitchTo + '
Protocol!';
+ }
+ else if (message.startsWith('Could not retrieve case')){
+ flash.to('search-error').error = message;
+ }
+ else {
+ flash.to('search-error').error = 'Could not load the case ' + caseNo + ' due to: ' + message;
+ }
+ });
+
+
+ }
+ }
+ ]);
diff --git a/app/assets/javascripts/core.js b/app/assets/javascripts/core.js
index cc7ebb001..d9c482b04 100644
--- a/app/assets/javascripts/core.js
+++ b/app/assets/javascripts/core.js
@@ -78,7 +78,6 @@
//= require_tree ./services
//= require_tree ./values
//= require_tree ../templates
-//= require_tree ./components
//= require footer
//= require tether-shepherd/dist/js/tether
//= require tether-shepherd/dist/js/shepherd
diff --git a/app/assets/javascripts/core_stripped.js b/app/assets/javascripts/core_stripped.js
new file mode 100644
index 000000000..80fd30a3c
--- /dev/null
+++ b/app/assets/javascripts/core_stripped.js
@@ -0,0 +1,41 @@
+// This is a manifest file that'll be compiled into core.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
+// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// compiled file.
+//
+// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
+// about supported directives.
+//
+// This file loads all the below JavaScript files and can be very slow in the dev mode.
+//
+// This file is meant for the stripped down Angular Core app used by AgentQ.
+//
+//= require jquery
+
+
+//= require angular/angular
+
+//= require angular-resource/angular-resource
+//= require angular-cookies/angular-cookies
+//= require angular-route/angular-route
+//= require angular-sanitize/angular-sanitize
+//= require angular-ui-bootstrap/dist/ui-bootstrap
+//= require angular-rails-templates
+//= require splainer-search/splainer-search
+//= require angular-flash/dist/angular-flash
+//= require utilitiesModule
+//= require app_stripped
+//= require routes
+//= require_tree ./components
+//= require_tree ./controllers
+//= require_tree ./directives
+//= require_tree ./factories
+//= require_tree ./filters
+//= require_tree ./services
+//= require_tree ./values
+//= require_tree ../templates
+//= require_tree ./components
diff --git a/app/assets/javascripts/directives/queriesStripped.js b/app/assets/javascripts/directives/queriesStripped.js
new file mode 100644
index 000000000..26cf1e02d
--- /dev/null
+++ b/app/assets/javascripts/directives/queriesStripped.js
@@ -0,0 +1,14 @@
+'use strict';
+
+angular.module('QuepidApp')
+ .directive('queriesStripped', [
+ function () {
+ return {
+ restrict: 'E',
+ transclude: true,
+ controller: 'QueriesStrippedCtrl',
+ templateUrl: 'views/queries-stripped.html',
+ replace: true
+ };
+ }
+ ]);
diff --git a/app/assets/javascripts/factories/TryFactory.js b/app/assets/javascripts/factories/TryFactory.js
index f764d0bf6..7aa2a1a80 100644
--- a/app/assets/javascripts/factories/TryFactory.js
+++ b/app/assets/javascripts/factories/TryFactory.js
@@ -40,6 +40,7 @@
self.args = data.args;
self.deleted = false;
self.escapeQuery = data.escape_query;
+ self.backgroundQueries = data.background_queries
self.apiMethod = data.api_method;
self.customHeaders = data.custom_headers;
self.fieldSpec = data.field_spec;
diff --git a/app/assets/javascripts/routes.js b/app/assets/javascripts/routes.js
index 974b61e84..5352189e4 100644
--- a/app/assets/javascripts/routes.js
+++ b/app/assets/javascripts/routes.js
@@ -33,6 +33,11 @@ angular.module('QuepidApp')
controller: 'MainCtrl',
reloadOnSearch: false
})
+ .when('/case/:caseNo/query/:queryNo', {
+ templateUrl: 'views/queriesStripped.html',
+ controller: 'StrippedCtrl',
+ reloadOnSearch: false
+ })
.when('/cases', {
templateUrl: 'views/cases/index.html',
controller: 'CasesCtrl'
diff --git a/app/assets/javascripts/services/queriesSvc.js b/app/assets/javascripts/services/queriesSvc.js
index f279f1ba6..52e43278d 100644
--- a/app/assets/javascripts/services/queriesSvc.js
+++ b/app/assets/javascripts/services/queriesSvc.js
@@ -100,6 +100,10 @@ angular.module('QuepidApp')
// custom parser...
passedInSettings.searchEngine = 'solr';
}
+
+ if (passedInSettings.backgroundQueries) {
+ // Similar to how 'static' works, if we have
+ }
else if (passedInSettings.searchEngine === 'searchapi'){
/*jshint evil:true */
eval(passedInSettings.mapperCode);
diff --git a/app/assets/javascripts/services/querySnapshotSvc.js b/app/assets/javascripts/services/querySnapshotSvc.js
index 15c58477e..51fb6e012 100644
--- a/app/assets/javascripts/services/querySnapshotSvc.js
+++ b/app/assets/javascripts/services/querySnapshotSvc.js
@@ -108,7 +108,8 @@ angular.module('QuepidApp')
});
};
- this.addSnapshot = function(name, recordDocumentFields, queries) {
+
+ this.createSnapshotPayload = function(name, recordDocumentFields, recordExplain, queries) {
// we may want to refactor the payload structure in the future.
var docs = {};
var queriesPayload = {};
@@ -129,8 +130,12 @@ angular.module('QuepidApp')
// Save all matches
angular.forEach(query.docs, function(doc) {
-
- var docPayload = {'id': doc.id, 'explain': doc.explain().rawStr(), 'rated_only': false};
+ let explain = null;
+ if (recordExplain) {
+ explain = doc.explain().rawStr();
+ }
+ var docPayload = {'id': doc.id, 'explain': explain, 'rated_only': false};
+
if (recordDocumentFields) {
var fields = {};
angular.forEach(Object.values(doc.subsList), function(field) {
@@ -161,15 +166,22 @@ angular.module('QuepidApp')
});
});
- var saved = {
+ var payload = {
'snapshot': {
'name': name,
'docs': docs,
'queries': queriesPayload
}
};
+
+ return payload;
+ };
+
+ this.addSnapshot = function(name, recordDocumentFields, queries) {
+
+ payload = createSnapshotPayload(name, recordDocumentFields, recordMatch, queries);
- return $http.post('api/cases/' + caseNo + '/snapshots', saved)
+ return $http.post('api/cases/' + caseNo + '/snapshots', payload)
.then(function(response) {
return addSnapshotResp([response.data])
.then(function() {
diff --git a/app/assets/templates/views/devQueryParams.html b/app/assets/templates/views/devQueryParams.html
index aa434cb06..7d84fce32 100644
--- a/app/assets/templates/views/devQueryParams.html
+++ b/app/assets/templates/views/devQueryParams.html
@@ -252,7 +252,35 @@ Tuning Knobs
-
+
+
+
+
+
+
+
+
+ Background Run Queries
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/assets/templates/views/queries-stripped.html b/app/assets/templates/views/queries-stripped.html
new file mode 100644
index 000000000..90d570fa9
--- /dev/null
+++ b/app/assets/templates/views/queries-stripped.html
@@ -0,0 +1,22 @@
+
diff --git a/app/assets/templates/views/queriesStripped.html b/app/assets/templates/views/queriesStripped.html
new file mode 100644
index 000000000..fa1e42b2e
--- /dev/null
+++ b/app/assets/templates/views/queriesStripped.html
@@ -0,0 +1,28 @@
+
diff --git a/app/controllers/api/v1/agent_q_controller.rb b/app/controllers/api/v1/agent_q_controller.rb
new file mode 100644
index 000000000..4fbfdde69
--- /dev/null
+++ b/app/controllers/api/v1/agent_q_controller.rb
@@ -0,0 +1,87 @@
+# frozen_string_literal: true
+
+require 'ferrum'
+require 'benchmark'
+
+# Note: Auto reloading this file appears to not work. If you change the file, quit Rails and restart it.
+# I suspect something about how we are talking to Ferrum/Chrome.
+#
+# Also browser.quit causes Rails to quit too!
+#
+# rubocop:disable Layout/LineLength
+# rubocop:disable Metrics/MethodLength
+module Api
+ module V1
+ class AgentQController < Api::ApiController
+ #skip_before_action :require_login
+ skip_before_action :verify_authenticity_token, only: [ :fetch ]
+ @browser = nil
+
+ def fetch
+
+ api_key = nil
+ if @current_user.api_keys.empty?
+ api_key = @current_user.api_keys.create! token: SecureRandom.hex
+ puts "we made a api"
+ else
+ api_key = @current_user.api_keys.first
+ end
+
+ puts "api_key is #{api_key.token_digest}"
+
+
+ if @browser.nil?
+ puts 'creating Ferrum Browser'
+ # Launch Ferrum browser
+ @browser = Ferrum::Browser.new({
+ process_timeout: 5, headless: true,
+ window_size: [ 1280, 800 ],
+ browser_options: { 'no-sandbox': nil },
+ timeout: 60,
+ pending_connection_errors: false
+
+ })
+ end
+ @browser.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
+ page = @browser.create_page
+ page.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
+
+ Benchmark.measure do
+ # Perform a GET request
+ page.go_to('http://localhost:3000/case/4/query/5')
+ # page.network.wait_for_idle
+ end
+
+ start_time = Time.zone.now
+
+ counter = 30
+ # Run the loop for a maximum of 5 seconds
+ # Timeout.timeout(60) do
+ loop do
+ break unless page.at_css('.snapshot-payload').nil?
+ break if counter.zero?
+
+ # Sleep for a short duration before checking the condition again
+
+ counter -= 1
+ sleep 1
+ end
+
+ puts "Condition met after #{Time.zone.now - start_time} seconds."
+
+ node = page.at_css('.snapshot-payload')
+
+ # @@browser.quit
+
+ if node
+ render json: node.text, status: :ok
+ else
+ render json: { agentq_error: 'boom', counter: counter }, status: :internal_server_error
+ end
+ # Close the browser
+ end
+ end
+ end
+end
+# rubocop:enable Layout/LineLength
+# rubocop:enable Metrics/MethodLength
diff --git a/app/controllers/api/v1/queries_controller.rb b/app/controllers/api/v1/queries_controller.rb
index 6b2d695de..91d1ae7b6 100644
--- a/app/controllers/api/v1/queries_controller.rb
+++ b/app/controllers/api/v1/queries_controller.rb
@@ -35,7 +35,7 @@ def create
if @query.save
@query.insert_at(params[:position].to_i) if params[:position]
- @case.save
+ # @case.save # Having this line made inserting a new case trigger a bunch of updates which was slow.
Analytics::Tracker.track_query_created_event current_user, @query
@@ -82,8 +82,8 @@ def destroy
# Make sure queries have the right `arranged_next` and `arranged_at`
# values after the query has been removed
- @case.rearrange_queries
- @case.save
+ # @case.rearrange_queries // super slow with lots of queires
+ # @case.save
head :no_content
end
diff --git a/app/controllers/core_controller.rb b/app/controllers/core_controller.rb
index ff38171fa..229b99210 100755
--- a/app/controllers/core_controller.rb
+++ b/app/controllers/core_controller.rb
@@ -6,6 +6,19 @@ class CoreController < ApplicationController
before_action :populate_from_params, except: :new
skip_before_action :check_for_announcement
+ def require_login
+ @current_user = User.find(3)
+ end
+
+ # Spiking out can we make an API public?
+ def authenticate_api!
+ set_case
+ return true if @case&.public? || current_user
+
+ render json: { reason: 'Unauthorized!' },
+ status: :unauthorized
+ end
+
def index
end
diff --git a/app/controllers/core_stripped_controller.rb b/app/controllers/core_stripped_controller.rb
new file mode 100755
index 000000000..e72ea55d8
--- /dev/null
+++ b/app/controllers/core_stripped_controller.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+# This hosts the stripped down version Angular 1 application that runs in the client.
+# It is meant to wrap up the business logic used in interacting with a search endpoint
+# and abstract that all away from the caller. We create a HTML page that is populated
+# with the resulting query/docs. Currently using the "snapshot" JSON format.
+# It is meant to be called by agent_q_controller.rb.
+#
+class CoreStrippedController < ApplicationController
+ include ApiKeyAuthenticatable
+ skip_before_action :check_for_announcement
+ before_action :authenticate_with_api_key! # , only: [:index]
+
+ def require_login
+ if request.headers['Authorization']
+ token = request.headers['Authorization']
+ token = token[7..] # chop off 'Bearer ' portion of the header
+ current_api_key = ApiKey.find_by token_digest: token
+
+ @current_user = current_api_key.user
+ end
+ end
+
+ # Spiking out can we make an API public?
+ def authenticate_api!
+ set_case
+ return true if @case&.public? || current_user
+
+ render json: { reason: 'Unauthorized!' },
+ status: :unauthorized
+ end
+
+ def index
+ end
+
+end
diff --git a/app/views/core_stripped/index.html.erb b/app/views/core_stripped/index.html.erb
new file mode 100755
index 000000000..38a2c9b3f
--- /dev/null
+++ b/app/views/core_stripped/index.html.erb
@@ -0,0 +1,17 @@
+
+
+
diff --git a/app/views/layouts/core_stripped.html.erb b/app/views/layouts/core_stripped.html.erb
new file mode 100755
index 000000000..6f8e10803
--- /dev/null
+++ b/app/views/layouts/core_stripped.html.erb
@@ -0,0 +1,35 @@
+
+
+
+
+Quepid -- Relevant Search Solved
+
+<%= csrf_meta_tags %>
+
+
+
+
+
+
+
+ <%= yield %>
+
+
+
+ <%= javascript_include_tag 'core_stripped' %>
+
+
+
+
+
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
index 2c20284dc..584d77af2 100755
--- a/config/initializers/assets.rb
+++ b/config/initializers/assets.rb
@@ -15,8 +15,8 @@
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
-Rails.application.config.assets.precompile += %w[ core.css core.js admin.css admin_users.css admin.js admin_users.js
- analytics.js ]
+Rails.application.config.assets.precompile += %w[ core.css core.js core_stripped.js ]
+Rails.application.config.assets.precompile += %w[ admin.css admin_users.css admin.js admin_users.js analytics.js ]
Rails.application.config.assets.precompile += %w[ application_spec.js ]
# CSS from node modules
diff --git a/config/routes.rb b/config/routes.rb
index 43425bc2e..3d80520c1 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -11,6 +11,7 @@
get 'proxy/fetch'
post 'proxy/fetch'
+
mount ActiveStorageDB::Engine => '/active_storage_db'
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
@@ -119,6 +120,9 @@
get 'test_exception' => 'api#test_exception'
scope module: :v1, constraints: ApiConstraint.new(version: 1, default: true) do
+
+ get '/agent_q/fetch' => 'agent_q#fetch'
+
resources :users, only: [ :index, :show, :update ] do
get '/current' => 'current_user#show', on: :collection
end
@@ -241,6 +245,7 @@
# Routes handled by angular
get '/case/:id(/try/:try_number)' => 'core#index', as: :case_core
+ get '/case/:id(/query/:queryNo)' => 'core_stripped#index'
get '/cases/new' => 'core#new', as: :case_new
get '/cases' => 'core#index'
get '/case' => 'core#index'
From c2ddde4543d345192a607802f62d2ae6d3731646 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Fri, 8 Mar 2024 11:45:09 -0500
Subject: [PATCH 02/19] lint
---
.../javascripts/controllers/mainCtrl.js | 7 ++---
.../controllers/queriesStrippedCtrl.js | 4 +--
.../javascripts/controllers/strippedCtrl.js | 28 ++++++-------------
.../javascripts/factories/TryFactory.js | 2 +-
.../javascripts/services/querySnapshotSvc.js | 2 +-
5 files changed, 15 insertions(+), 28 deletions(-)
diff --git a/app/assets/javascripts/controllers/mainCtrl.js b/app/assets/javascripts/controllers/mainCtrl.js
index 3b856b4da..2b9ecfd5b 100644
--- a/app/assets/javascripts/controllers/mainCtrl.js
+++ b/app/assets/javascripts/controllers/mainCtrl.js
@@ -107,9 +107,9 @@ angular.module('QuepidApp')
bootstrapped = true;
- console.log(queriesSvc.queryArray().length)
+ console.log(queriesSvc.queryArray().length);
if (queriesSvc.queryArray().length <= 410) {
- console.log("About to call queriesSvc.searchAll")
+ console.log('About to call queriesSvc.searchAll');
return queriesSvc.searchAll()
.then(function() {
flash.success = 'All queries finished successfully!';
@@ -123,7 +123,7 @@ angular.module('QuepidApp')
else {
queriesSvc.requireManualTrigger = true;
flash.success = 'You have ' + queriesSvc.queryArray().length + ' queries in this case and must manually trigger running this!';
- return
+ return;
}
}
});
@@ -153,7 +153,6 @@ angular.module('QuepidApp')
}
else if ( caseNo > 0 ) {
queriesSvc.querySearchPromiseReset();
- console.log("about to bootstrapCase")
bootstrapCase()
.then(function() {
loadQueries();
diff --git a/app/assets/javascripts/controllers/queriesStrippedCtrl.js b/app/assets/javascripts/controllers/queriesStrippedCtrl.js
index ab8a2f6ee..5d7ce9500 100644
--- a/app/assets/javascripts/controllers/queriesStrippedCtrl.js
+++ b/app/assets/javascripts/controllers/queriesStrippedCtrl.js
@@ -16,8 +16,6 @@ angular.module('QuepidApp')
$scope.queriesSvc = queriesSvc;
$scope.caseSvc = caseSvc;
- console.log("HI THERE")
-
$scope.queries = {};
$scope.queries.queriesChanged = function() {
@@ -37,7 +35,7 @@ angular.module('QuepidApp')
$scope.snapshotPayload = function() {
if (!$scope.searching()){
- return querySnapshotSvc.createSnapshotPayload("", true, false, queriesSvc.queryArray());
+ return querySnapshotSvc.createSnapshotPayload('', true, false, queriesSvc.queryArray());
}
}
diff --git a/app/assets/javascripts/controllers/strippedCtrl.js b/app/assets/javascripts/controllers/strippedCtrl.js
index e0a2e0d63..2befa371b 100644
--- a/app/assets/javascripts/controllers/strippedCtrl.js
+++ b/app/assets/javascripts/controllers/strippedCtrl.js
@@ -103,24 +103,15 @@ angular.module('QuepidApp')
bootstrapped = true;
- console.log(queriesSvc.queryArray().length)
- if (queriesSvc.queryArray().length <= 410) {
- console.log("About to call queriesSvc.searchAll")
- return queriesSvc.searchAll()
- .then(function() {
- flash.success = 'All queries finished successfully!';
- }, function(errorMsg) {
- var mainErrorMsg = 'Some queries failed to resolve!';
-
- flash.error = mainErrorMsg;
- flash.to('search-error').error = errorMsg;
- });
- }
- else {
- queriesSvc.requireManualTrigger = true;
- flash.success = 'You have ' + queriesSvc.queryArray().length + ' queries in this case and must manually trigger running this!';
- return
- }
+ return queriesSvc.searchAll()
+ .then(function() {
+ flash.success = 'All queries finished successfully!';
+ }, function(errorMsg) {
+ var mainErrorMsg = 'Some queries failed to resolve!';
+
+ flash.error = mainErrorMsg;
+ flash.to('search-error').error = errorMsg;
+ });
}
});
});
@@ -140,7 +131,6 @@ angular.module('QuepidApp')
}
else if ( caseNo > 0 ) {
queriesSvc.querySearchPromiseReset();
- console.log("about to bootstrapCase")
bootstrapCase()
.then(function() {
loadQueries();
diff --git a/app/assets/javascripts/factories/TryFactory.js b/app/assets/javascripts/factories/TryFactory.js
index 7aa2a1a80..48de322bf 100644
--- a/app/assets/javascripts/factories/TryFactory.js
+++ b/app/assets/javascripts/factories/TryFactory.js
@@ -40,7 +40,7 @@
self.args = data.args;
self.deleted = false;
self.escapeQuery = data.escape_query;
- self.backgroundQueries = data.background_queries
+ self.backgroundQueries = data.background_queries;
self.apiMethod = data.api_method;
self.customHeaders = data.custom_headers;
self.fieldSpec = data.field_spec;
diff --git a/app/assets/javascripts/services/querySnapshotSvc.js b/app/assets/javascripts/services/querySnapshotSvc.js
index 51fb6e012..9c9e93de1 100644
--- a/app/assets/javascripts/services/querySnapshotSvc.js
+++ b/app/assets/javascripts/services/querySnapshotSvc.js
@@ -179,7 +179,7 @@ angular.module('QuepidApp')
this.addSnapshot = function(name, recordDocumentFields, queries) {
- payload = createSnapshotPayload(name, recordDocumentFields, recordMatch, queries);
+ let payload = this.createSnapshotPayload(name, recordDocumentFields, true, queries);
return $http.post('api/cases/' + caseNo + '/snapshots', payload)
.then(function(response) {
From 1f9a3c158fdd87a95ffe0179752c6d860608299c Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 06:19:16 -0400
Subject: [PATCH 03/19] associate search end point with team!
---
app/assets/javascripts/controllers/mainCtrl.js | 2 +-
lib/tasks/sample_data.thor | 2 ++
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/app/assets/javascripts/controllers/mainCtrl.js b/app/assets/javascripts/controllers/mainCtrl.js
index 2b9ecfd5b..b28b09918 100644
--- a/app/assets/javascripts/controllers/mainCtrl.js
+++ b/app/assets/javascripts/controllers/mainCtrl.js
@@ -108,7 +108,7 @@ angular.module('QuepidApp')
bootstrapped = true;
console.log(queriesSvc.queryArray().length);
- if (queriesSvc.queryArray().length <= 410) {
+ if (queriesSvc.queryArray().length <= 29) {
console.log('About to call queriesSvc.searchAll');
return queriesSvc.searchAll()
.then(function() {
diff --git a/lib/tasks/sample_data.thor b/lib/tasks/sample_data.thor
index b3b6814f6..182fbab47 100644
--- a/lib/tasks/sample_data.thor
+++ b/lib/tasks/sample_data.thor
@@ -227,6 +227,8 @@ class SampleData < Thor
osc.members << osc_member_user unless osc.members.include?(osc_member_user)
osc.members << realistic_activity_user unless osc.members.include?(realistic_activity_user)
osc.cases << tens_of_queries_case unless osc.members.include?(tens_of_queries_case)
+ osc.search_endpoints << statedecoded_solr_endpoint unless osc.search_endpoints.include?(statedecoded_solr_endpoint)
+
print_step 'End of seeding teams................'
# Books
From 7baab3966712f79056d2a9ee727937930acc3a2e Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 06:19:30 -0400
Subject: [PATCH 04/19] position is good
---
app/assets/javascripts/components/export_case/_modal.html | 2 +-
app/assets/javascripts/services/caseCSVSvc.js | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/app/assets/javascripts/components/export_case/_modal.html b/app/assets/javascripts/components/export_case/_modal.html
index 87c50f1d6..48ab1964a 100644
--- a/app/assets/javascripts/components/export_case/_modal.html
+++ b/app/assets/javascripts/components/export_case/_modal.html
@@ -29,7 +29,7 @@ Export Case: {{ ctrl.theCase.ca
Detailed export is only supported from the individual Case view.
- CSV file with Team Name,Case Name,Case ID,Query Text,Doc ID,Title,Rating,Field1,...,FieldN
where Field1,...,FieldN
are specified under Settings in the Displayed Fields field.
+ CSV file with Team Name,Case Name,Case ID,Query Text,Doc ID,Position,Title,Rating,Field1,...,FieldN
where Field1,...,FieldN
are specified under Settings in the Displayed Fields field.
diff --git a/app/assets/javascripts/services/caseCSVSvc.js b/app/assets/javascripts/services/caseCSVSvc.js
index 871281b29..23f16e74e 100644
--- a/app/assets/javascripts/services/caseCSVSvc.js
+++ b/app/assets/javascripts/services/caseCSVSvc.js
@@ -79,6 +79,7 @@
'Case ID',
'Query Text',
'Doc ID',
+ 'Doc Position',
'Title',
'Rating',
];
@@ -353,7 +354,7 @@
csvContent += dataString + EOL;
}
else {
- angular.forEach(docs, function (doc) {
+ angular.forEach(docs, function (doc, index) {
var dataString;
var infoArray = [];
@@ -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()));
From 4150b878ca5085b56d71ac23be228401c44c3ce6 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 06:35:08 -0400
Subject: [PATCH 05/19] infrastructure around running a background job...
---
app/controllers/api/v1/agent_q_controller.rb | 52 +++++----
app/jobs/run_case_job.rb | 106 +++++++++++++++++++
config/initializers/sidekiq.rb | 9 +-
config/routes.rb | 1 +
4 files changed, 145 insertions(+), 23 deletions(-)
create mode 100644 app/jobs/run_case_job.rb
diff --git a/app/controllers/api/v1/agent_q_controller.rb b/app/controllers/api/v1/agent_q_controller.rb
index 4fbfdde69..a6fd91336 100644
--- a/app/controllers/api/v1/agent_q_controller.rb
+++ b/app/controllers/api/v1/agent_q_controller.rb
@@ -16,6 +16,13 @@ class AgentQController < Api::ApiController
#skip_before_action :require_login
skip_before_action :verify_authenticity_token, only: [ :fetch ]
@browser = nil
+
+ def trigger
+ kase = Case.find(4)
+ RunCaseJob.perform_later kase.owner, kase
+
+ render json: { message: 'scheduled' }, status: :ok
+ end
def fetch
@@ -46,30 +53,33 @@ def fetch
page = @browser.create_page
page.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
- Benchmark.measure do
+ result = Benchmark.measure do
# Perform a GET request
page.go_to('http://localhost:3000/case/4/query/5')
# page.network.wait_for_idle
- end
-
- start_time = Time.zone.now
-
- counter = 30
- # Run the loop for a maximum of 5 seconds
- # Timeout.timeout(60) do
- loop do
- break unless page.at_css('.snapshot-payload').nil?
- break if counter.zero?
-
- # Sleep for a short duration before checking the condition again
-
- counter -= 1
- sleep 1
- end
-
- puts "Condition met after #{Time.zone.now - start_time} seconds."
-
- node = page.at_css('.snapshot-payload')
+
+
+ start_time = Time.zone.now
+
+ counter = 30
+ # Run the loop for a maximum of 5 seconds
+ # Timeout.timeout(60) do
+ loop do
+ break unless page.at_css('.snapshot-payload').nil?
+ break if counter.zero?
+
+ # Sleep for a short duration before checking the condition again
+
+ counter -= 1
+ sleep 1
+ end
+
+ puts "Condition met after #{Time.zone.now - start_time} seconds."
+
+ node = page.at_css('.snapshot-payload')
+ end
+
+ puts result
# @@browser.quit
diff --git a/app/jobs/run_case_job.rb b/app/jobs/run_case_job.rb
new file mode 100644
index 000000000..bde762430
--- /dev/null
+++ b/app/jobs/run_case_job.rb
@@ -0,0 +1,106 @@
+# frozen_string_literal: true
+
+class RunCaseJob < ApplicationJob
+ queue_as :single
+ sidekiq_options retry: 0
+
+ @@browser = nil
+
+ def perform user, kase
+
+ api_key = nil
+ if user.api_keys.empty?
+ api_key = user.api_keys.create! token: SecureRandom.hex
+ puts "we made a api"
+ else
+ api_key = user.api_keys.first
+ end
+
+ puts "api_key is #{api_key.token_digest}"
+
+ retries = 3
+
+ begin
+ if @@browser.nil?
+ puts 'creating Ferrum Browser'
+ # Launch Ferrum browser
+
+
+ @@browser = Ferrum::Browser.new({
+ process_timeout: 5, headless: 'new',
+ window_size: [ 1280, 800 ],
+ browser_options: { 'no-sandbox': nil },
+ timeout: 60,
+ pending_connection_errors: false,
+ js_errors:false,
+ browser_options: { 'no-sandbox': nil }
+
+ })
+ end
+
+ #@browser.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
+ page = @@browser.create_page
+ page.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
+
+
+ kase.queries.each do | query |
+ result = Benchmark.measure do
+ # Perform a GET request
+ #url = "http://localhost:3000/case/#{kase.id}/query/#{query.id}"
+ url = "http://localhost:3000/case/#{kase.id}/query/#{query.id}"
+ puts url
+ page.go_to(url)
+ page.network.wait_for_idle
+ end
+
+ puts result
+
+ start_time = Time.zone.now
+
+ counter = 30
+ # Run the loop for a maximum of 5 seconds
+ # Timeout.timeout(60) do
+ loop do
+ break unless page.at_css('.snapshot-payload').nil?
+ break if counter.zero?
+
+ # Sleep for a short duration before checking the condition again
+
+ counter -= 1
+ sleep 1
+ end
+
+ puts "Condition met after #{Time.zone.now - start_time} seconds."
+
+ node = page.at_css('.snapshot-payload')
+
+ if node.nil?
+ puts "We have a nil Node, so no response"
+ else
+ response = node.text
+ puts response
+ end
+ end
+
+ rescue Ferrum::BrowserError => e
+ retries -= 1
+ if retries > 0
+ puts "Ferrum BrowserError occurred: #{e.message}. Retrying..."
+ retry
+ else
+ puts "Ferrum BrowserError occurred: #{e.message}. Maximum retries reached."
+ # Handle the error or log it
+ end
+ rescue Ferrum::StatusError => e
+ puts "Ferrum StatusError occurred: #{e.message}."
+ ensure
+ #@browser.close if @browser # not yet released
+ puts "about to reset browser"
+ @@browser.reset
+ #@@browser.quit
+ #puts "browser quit"
+ end
+
+
+ end
+end
diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb
index 7f4dce654..dd840e34f 100644
--- a/config/initializers/sidekiq.rb
+++ b/config/initializers/sidekiq.rb
@@ -2,16 +2,21 @@
# Redis and Sidekiq is used only for sending Google Analytics updates, which is
# primarily used by the app.quepid.com install. This checks if we need Sidekiq.
-if Rails.application.config.google_analytics_enabled
+#if Rails.application.config.google_analytics_enabled
sidekiq_config = { url: ENV.fetch('REDIS_URL', nil),
ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
Sidekiq.configure_server do |config|
config.redis = sidekiq_config
+ config.capsule("unsafe") do |cap|
+ cap.concurrency = 1
+ cap.queues = %w[single]
+ end
+
end
Sidekiq.configure_client do |config|
config.redis = sidekiq_config
end
-end
+#end
diff --git a/config/routes.rb b/config/routes.rb
index 5b33f9ba3..c1dde0701 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -126,6 +126,7 @@
scope module: :v1, constraints: ApiConstraint.new(version: 1, default: true) do
get '/agent_q/fetch' => 'agent_q#fetch'
+ get '/agent_q/trigger' => 'agent_q#trigger'
resources :users, only: [ :index, :show, :update ] do
get '/current' => 'current_user#show', on: :collection
From dea549131f2dd5f9347638df8b9e8d79452cfac4 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 12:34:46 -0400
Subject: [PATCH 06/19] lots of changes to support backend job
---
Gemfile | 2 +-
.../javascripts/controllers/strippedCtrl.js | 3 +-
app/assets/javascripts/services/queriesSvc.js | 46 ++++++++-
app/controllers/api/v1/agent_q_controller.rb | 97 -------------------
.../api/v1/books/populate_controller.rb | 6 +-
.../api/v1/cases/jobs_controller.rb | 16 +++
app/controllers/api/v1/cases_controller.rb | 2 +-
.../api/v1/queries/agent_q_controller.rb | 97 +++++++++++++++++++
app/controllers/api/v1/queries_controller.rb | 14 ++-
.../authentication/current_case_manager.rb | 2 +-
app/controllers/core_controller.rb | 6 +-
app/controllers/core_stripped_controller.rb | 3 +-
app/jobs/run_case_job.rb | 60 ++++++------
app/jobs/run_case_job2.rb | 40 ++++++++
config/initializers/sidekiq.rb | 27 +++---
config/puma.rb | 3 +-
config/routes.rb | 13 +--
lib/tasks/sample_data.thor | 2 +-
test/integration/tls_flow_test.rb | 1 +
19 files changed, 270 insertions(+), 170 deletions(-)
delete mode 100644 app/controllers/api/v1/agent_q_controller.rb
create mode 100644 app/controllers/api/v1/cases/jobs_controller.rb
create mode 100644 app/controllers/api/v1/queries/agent_q_controller.rb
create mode 100644 app/jobs/run_case_job2.rb
diff --git a/Gemfile b/Gemfile
index 71d5529e9..0c1968bdf 100755
--- a/Gemfile
+++ b/Gemfile
@@ -92,4 +92,4 @@ end
gem 'importmap-rails', '~> 2.0'
-gem "ferrum", "~> 0.15"
+gem 'ferrum', '~> 0.15'
diff --git a/app/assets/javascripts/controllers/strippedCtrl.js b/app/assets/javascripts/controllers/strippedCtrl.js
index 2befa371b..529a19c67 100644
--- a/app/assets/javascripts/controllers/strippedCtrl.js
+++ b/app/assets/javascripts/controllers/strippedCtrl.js
@@ -18,6 +18,7 @@ angular.module('QuepidApp')
var caseNo = parseInt($routeParams.caseNo, 10);
var tryNo = parseInt($routeParams.tryNo, 10);
+ var queryNo = parseInt($routeParams.queryNo, 10);
var initialCaseNo = angular.copy(caseTryNavSvc.getCaseNo());
@@ -94,7 +95,7 @@ angular.module('QuepidApp')
.then(function() {
var bootstrapped = false;
- return queriesSvc.changeSettings(caseNo, newSettings)
+ return queriesSvc.changeSettings2(caseNo, queryNo, newSettings)
.then(function() {
if (!bootstrapped) {
flash.error = '';
diff --git a/app/assets/javascripts/services/queriesSvc.js b/app/assets/javascripts/services/queriesSvc.js
index 52e43278d..c600371ee 100644
--- a/app/assets/javascripts/services/queriesSvc.js
+++ b/app/assets/javascripts/services/queriesSvc.js
@@ -740,7 +740,7 @@ angular.module('QuepidApp')
let querySearchableDeferred = $q.defer();
function bootstrapQueries(caseNo) {
querySearchableDeferred = $q.defer();
- var path = 'api/cases/' + caseNo + '/queries?bootstrap=true';
+ var path = 'api/cases/' + caseNo + '/queries';
$http.get(path)
.then(function(response) {
@@ -758,6 +758,30 @@ angular.module('QuepidApp')
return querySearchableDeferred.promise;
}
+
+ function bootstrapQuery(caseNo, queryNo) {
+ querySearchableDeferred = $q.defer();
+ var path = 'api/cases/' + caseNo + '/queries/' + queryNo;
+
+ $http.get(path)
+ .then(function(response) {
+ that.queries = {};
+ // wrap the single result in an hash with an array.
+ let results = {display_order:[response.data.query_id], queries: [response.data]}
+
+ addQueriesFromResp(results);
+
+ querySearchableDeferred.resolve();
+ }, function(response) {
+ $log.debug('Failed to bootstrap queries: ', response);
+ return response;
+ }).catch(function(response) {
+ $log.debug('Failed to bootstrap queries');
+ return response;
+ });
+
+ return querySearchableDeferred.promise;
+ }
this.querySearchReady = function() {
$log.debug('PROMISE subscribed...');
@@ -788,6 +812,26 @@ angular.module('QuepidApp')
caseNo = newCaseNo;
return querySearchableDeferred.promise;
};
+
+ this.changeSettings2 = function(newCaseNo, queryNo, newSettings) {
+ currSettings = newSettings;
+
+ if (caseNo !== newCaseNo) {
+ scorerSvc.bootstrap(newCaseNo);
+ bootstrapQuery(newCaseNo, queryNo);
+ } else {
+ angular.forEach(this.queries, function(query) {
+ // TODO update settings for diffs
+ if (query.diff !== null) {
+ query.diff.fetch();
+ }
+ });
+ querySearchableDeferred.resolve();
+ }
+
+ caseNo = newCaseNo;
+ return querySearchableDeferred.promise;
+ };
this.searchAll = function() {
diff --git a/app/controllers/api/v1/agent_q_controller.rb b/app/controllers/api/v1/agent_q_controller.rb
deleted file mode 100644
index a6fd91336..000000000
--- a/app/controllers/api/v1/agent_q_controller.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-# frozen_string_literal: true
-
-require 'ferrum'
-require 'benchmark'
-
-# Note: Auto reloading this file appears to not work. If you change the file, quit Rails and restart it.
-# I suspect something about how we are talking to Ferrum/Chrome.
-#
-# Also browser.quit causes Rails to quit too!
-#
-# rubocop:disable Layout/LineLength
-# rubocop:disable Metrics/MethodLength
-module Api
- module V1
- class AgentQController < Api::ApiController
- #skip_before_action :require_login
- skip_before_action :verify_authenticity_token, only: [ :fetch ]
- @browser = nil
-
- def trigger
- kase = Case.find(4)
- RunCaseJob.perform_later kase.owner, kase
-
- render json: { message: 'scheduled' }, status: :ok
- end
-
- def fetch
-
- api_key = nil
- if @current_user.api_keys.empty?
- api_key = @current_user.api_keys.create! token: SecureRandom.hex
- puts "we made a api"
- else
- api_key = @current_user.api_keys.first
- end
-
- puts "api_key is #{api_key.token_digest}"
-
-
- if @browser.nil?
- puts 'creating Ferrum Browser'
- # Launch Ferrum browser
- @browser = Ferrum::Browser.new({
- process_timeout: 5, headless: true,
- window_size: [ 1280, 800 ],
- browser_options: { 'no-sandbox': nil },
- timeout: 60,
- pending_connection_errors: false
-
- })
- end
- @browser.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
- page = @browser.create_page
- page.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
-
- result = Benchmark.measure do
- # Perform a GET request
- page.go_to('http://localhost:3000/case/4/query/5')
- # page.network.wait_for_idle
-
-
- start_time = Time.zone.now
-
- counter = 30
- # Run the loop for a maximum of 5 seconds
- # Timeout.timeout(60) do
- loop do
- break unless page.at_css('.snapshot-payload').nil?
- break if counter.zero?
-
- # Sleep for a short duration before checking the condition again
-
- counter -= 1
- sleep 1
- end
-
- puts "Condition met after #{Time.zone.now - start_time} seconds."
-
- node = page.at_css('.snapshot-payload')
- end
-
- puts result
-
- # @@browser.quit
-
- if node
- render json: node.text, status: :ok
- else
- render json: { agentq_error: 'boom', counter: counter }, status: :internal_server_error
- end
- # Close the browser
- end
- end
- end
-end
-# rubocop:enable Layout/LineLength
-# rubocop:enable Metrics/MethodLength
diff --git a/app/controllers/api/v1/books/populate_controller.rb b/app/controllers/api/v1/books/populate_controller.rb
index 2c9f00205..204eebb63 100644
--- a/app/controllers/api/v1/books/populate_controller.rb
+++ b/app/controllers/api/v1/books/populate_controller.rb
@@ -20,13 +20,13 @@ class PopulateController < Api::ApiController
#
# rubocop:disable Layout/LineLength
def update
- puts "[PopulateController] Request Size is #{number_to_human_size(query_doc_pairs_params.to_s.bytesize)}"
+ # puts "[PopulateController] Request Size is #{number_to_human_size(query_doc_pairs_params.to_s.bytesize)}"
serialized_data = Marshal.dump(query_doc_pairs_params)
- puts "[PopulateController] the size of the serialized data is #{number_to_human_size(serialized_data.bytesize)}"
+ # puts "[PopulateController] the size of the serialized data is #{number_to_human_size(serialized_data.bytesize)}"
compressed_data = Zlib::Deflate.deflate(serialized_data)
- puts "[PopulateController] the size of the compressed data is #{number_to_human_size(compressed_data.bytesize)}"
+ # puts "[PopulateController] the size of the compressed data is #{number_to_human_size(compressed_data.bytesize)}"
@book.populate_file.attach(io: StringIO.new(compressed_data), filename: "book_populate_#{@book.id}.bin.zip",
content_type: 'application/zip')
PopulateBookJob.perform_later current_user, @book, @case
diff --git a/app/controllers/api/v1/cases/jobs_controller.rb b/app/controllers/api/v1/cases/jobs_controller.rb
new file mode 100644
index 000000000..192026cef
--- /dev/null
+++ b/app/controllers/api/v1/cases/jobs_controller.rb
@@ -0,0 +1,16 @@
+# frozen_string_literal: true
+
+module Api
+ module V1
+ module Cases
+ class JobsController < Api::ApiController
+ def trigger
+ kase = Case.find(4)
+ RunCaseJob2.perform_later kase.owner, kase
+
+ render json: { message: 'scheduled' }, status: :ok
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/api/v1/cases_controller.rb b/app/controllers/api/v1/cases_controller.rb
index d8c6bf4e8..aef0782f3 100644
--- a/app/controllers/api/v1/cases_controller.rb
+++ b/app/controllers/api/v1/cases_controller.rb
@@ -4,7 +4,7 @@ module Api
module V1
# rubocop:disable Metrics/ClassLength
class CasesController < Api::ApiController
- before_action :set_case, only: [ :show, :update, :destroy ]
+ before_action :set_case, only: [ :update, :destroy ]
before_action :case_with_all_the_bells_whistles, only: [ :show ]
before_action :check_case, only: [ :show, :update, :destroy ]
diff --git a/app/controllers/api/v1/queries/agent_q_controller.rb b/app/controllers/api/v1/queries/agent_q_controller.rb
new file mode 100644
index 000000000..228e6c702
--- /dev/null
+++ b/app/controllers/api/v1/queries/agent_q_controller.rb
@@ -0,0 +1,97 @@
+# frozen_string_literal: true
+
+require 'ferrum'
+require 'benchmark'
+
+# NOTE: Auto reloading this file appears to not work. If you change the file, quit Rails and restart it.
+# I suspect something about how we are talking to Ferrum/Chrome.
+#
+# Also browser.quit causes Rails to quit too!
+#
+# rubocop:disable Metrics/MethodLength
+module Api
+ module V1
+ module Queries
+ class AgentQController < Queries::ApplicationController
+ # skip_before_action :require_login
+ skip_before_action :verify_authenticity_token, only: [ :fetch ]
+ before_action :set_case, only: [ :fetch ]
+ before_action :check_case, only: [ :fetch ]
+ before_action :set_case_query, only: [ :fetch ]
+ before_action :check_query, only: [ :fetch ]
+ @browser = nil
+
+ def fetch
+ api_key = nil
+ if @current_user.api_keys.empty?
+ api_key = @current_user.api_keys.create! token: SecureRandom.hex
+ puts 'we made a api'
+ else
+ api_key = @current_user.api_keys.first
+ end
+
+ puts "api_key is #{api_key.token_digest}"
+
+ if @browser.nil?
+ puts 'creating Ferrum Browser'
+ # Launch Ferrum browser
+ @browser = Ferrum::Browser.new({
+ process_timeout: 5, headless: true,
+ window_size: [ 1280, 800 ],
+ browser_options: { 'no-sandbox': nil },
+ timeout: 60,
+ pending_connection_errors: false
+
+ })
+ end
+ # @browser.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
+ page = @browser.create_page
+ page.headers.set(
+ { 'Authorization' => "Bearer #{api_key.token_digest}" }
+ )
+
+ counter = 30
+ result = Benchmark.measure do
+ # Perform a GET request
+ #
+ # api_case_query_agent_q_path
+ puts "root url is #{root_url}"
+ quepid_url = "#{root_url}case/#{@case.id}/query/#{@query.id}"
+ # quepid_url = api_case_query_agent_q_url @case, @query
+ puts "looking up #{quepid_url}"
+ page.go_to(quepid_url)
+ # page.network.wait_for_idle
+
+ start_time = Time.zone.now
+
+ # Run the loop for a maximum of 5 seconds
+ # Timeout.timeout(60) do
+ loop do
+ break unless page.at_css('.snapshot-payload').nil?
+ break if counter.zero?
+
+ # Sleep for a short duration before checking the condition again
+
+ counter -= 1
+ sleep 1
+ end
+ puts "Condition met after #{Time.zone.now - start_time} seconds."
+ end
+ puts result
+
+ node = page.at_css('.snapshot-payload')
+
+ # @@browser.quit
+
+ if node
+ render json: node.text, status: :ok
+ else
+ render json: { agentq_error: 'boom', counter: counter }, status: :internal_server_error
+ end
+ # Close the browser
+ end
+ end
+ end
+ end
+end
+# rubocop:enable Metrics/MethodLength
diff --git a/app/controllers/api/v1/queries_controller.rb b/app/controllers/api/v1/queries_controller.rb
index 91d1ae7b6..41c1cc87b 100644
--- a/app/controllers/api/v1/queries_controller.rb
+++ b/app/controllers/api/v1/queries_controller.rb
@@ -5,8 +5,8 @@ module V1
class QueriesController < Api::ApiController
before_action :set_case
before_action :check_case
- before_action :set_query, only: [ :update, :destroy ]
- before_action :check_query, only: [ :update, :destroy ]
+ before_action :set_query, only: [ :update, :destroy, :show ]
+ before_action :check_query, only: [ :update, :destroy, :show ]
def index
@queries = @case.queries.includes([ :ratings ])
@@ -16,6 +16,9 @@ def index
respond_with @queries, @display_order
end
+ def show
+ end
+
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def create
@@ -35,7 +38,8 @@ def create
if @query.save
@query.insert_at(params[:position].to_i) if params[:position]
- # @case.save # Having this line made inserting a new case trigger a bunch of updates which was slow.
+ # next line I think deals with positioning
+ @case.save # Having this line made inserting a new case trigger a bunch of updates which was slow.
Analytics::Tracker.track_query_created_event current_user, @query
@@ -82,8 +86,8 @@ def destroy
# Make sure queries have the right `arranged_next` and `arranged_at`
# values after the query has been removed
- # @case.rearrange_queries // super slow with lots of queires
- # @case.save
+ @case.rearrange_queries # super slow with lots of queires
+ @case.save
head :no_content
end
diff --git a/app/controllers/concerns/authentication/current_case_manager.rb b/app/controllers/concerns/authentication/current_case_manager.rb
index 8698bb6c4..9dc57e1d7 100644
--- a/app/controllers/concerns/authentication/current_case_manager.rb
+++ b/app/controllers/concerns/authentication/current_case_manager.rb
@@ -81,7 +81,7 @@ def case_with_all_the_bells_whistles
.cases_involved_with
.where(id: params[:case_id])
.includes(:tries )
- .preload([ queries: [ :ratings ], tries: [ :curator_variables, :search_endpoint ] ])
+ .preload([ :queries, { tries: [ :curator_variables, :search_endpoint ] } ])
.order('tries.try_number DESC')
.first
end
diff --git a/app/controllers/core_controller.rb b/app/controllers/core_controller.rb
index 229b99210..895b8290f 100755
--- a/app/controllers/core_controller.rb
+++ b/app/controllers/core_controller.rb
@@ -6,9 +6,9 @@ class CoreController < ApplicationController
before_action :populate_from_params, except: :new
skip_before_action :check_for_announcement
- def require_login
- @current_user = User.find(3)
- end
+ #def require_login
+ # @current_user = User.find(3)
+ #end
# Spiking out can we make an API public?
def authenticate_api!
diff --git a/app/controllers/core_stripped_controller.rb b/app/controllers/core_stripped_controller.rb
index e72ea55d8..c6dd36051 100755
--- a/app/controllers/core_stripped_controller.rb
+++ b/app/controllers/core_stripped_controller.rb
@@ -5,7 +5,7 @@
# and abstract that all away from the caller. We create a HTML page that is populated
# with the resulting query/docs. Currently using the "snapshot" JSON format.
# It is meant to be called by agent_q_controller.rb.
-#
+#
class CoreStrippedController < ApplicationController
include ApiKeyAuthenticatable
skip_before_action :check_for_announcement
@@ -32,5 +32,4 @@ def authenticate_api!
def index
end
-
end
diff --git a/app/jobs/run_case_job.rb b/app/jobs/run_case_job.rb
index bde762430..579263a10 100644
--- a/app/jobs/run_case_job.rb
+++ b/app/jobs/run_case_job.rb
@@ -7,100 +7,94 @@ class RunCaseJob < ApplicationJob
@@browser = nil
def perform user, kase
-
api_key = nil
if user.api_keys.empty?
api_key = user.api_keys.create! token: SecureRandom.hex
- puts "we made a api"
+ puts 'we made a api'
else
api_key = user.api_keys.first
end
-
+
puts "api_key is #{api_key.token_digest}"
-
+
retries = 3
-
+
begin
if @@browser.nil?
puts 'creating Ferrum Browser'
# Launch Ferrum browser
-
-
+
@@browser = Ferrum::Browser.new({
process_timeout: 5, headless: 'new',
window_size: [ 1280, 800 ],
browser_options: { 'no-sandbox': nil },
timeout: 60,
pending_connection_errors: false,
- js_errors:false,
+ js_errors: false,
browser_options: { 'no-sandbox': nil }
-
+
})
end
-
- #@browser.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
+
+ # @browser.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
page = @@browser.create_page
page.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
-
-
- kase.queries.each do | query |
+
+ kase.queries.each do |query|
result = Benchmark.measure do
# Perform a GET request
- #url = "http://localhost:3000/case/#{kase.id}/query/#{query.id}"
+ # url = "http://localhost:3000/case/#{kase.id}/query/#{query.id}"
url = "http://localhost:3000/case/#{kase.id}/query/#{query.id}"
puts url
page.go_to(url)
page.network.wait_for_idle
end
-
+
puts result
-
+
start_time = Time.zone.now
-
+
counter = 30
# Run the loop for a maximum of 5 seconds
# Timeout.timeout(60) do
loop do
break unless page.at_css('.snapshot-payload').nil?
break if counter.zero?
-
+
# Sleep for a short duration before checking the condition again
-
+
counter -= 1
sleep 1
end
-
+
puts "Condition met after #{Time.zone.now - start_time} seconds."
-
+
node = page.at_css('.snapshot-payload')
-
+
if node.nil?
- puts "We have a nil Node, so no response"
+ puts 'We have a nil Node, so no response'
else
response = node.text
puts response
end
end
-
rescue Ferrum::BrowserError => e
retries -= 1
- if retries > 0
+ if retries.positive?
puts "Ferrum BrowserError occurred: #{e.message}. Retrying..."
retry
else
puts "Ferrum BrowserError occurred: #{e.message}. Maximum retries reached."
# Handle the error or log it
- end
+ end
rescue Ferrum::StatusError => e
puts "Ferrum StatusError occurred: #{e.message}."
ensure
- #@browser.close if @browser # not yet released
- puts "about to reset browser"
+ # @browser.close if @browser # not yet released
+ puts 'about to reset browser'
@@browser.reset
- #@@browser.quit
- #puts "browser quit"
+ # @@browser.quit
+ # puts "browser quit"
end
-
-
end
end
diff --git a/app/jobs/run_case_job2.rb b/app/jobs/run_case_job2.rb
new file mode 100644
index 000000000..f46e94ffc
--- /dev/null
+++ b/app/jobs/run_case_job2.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class RunCaseJob2 < ApplicationJob
+ queue_as :single
+ sidekiq_options retry: 0
+
+ def perform user, kase
+ api_key = nil
+ if user.api_keys.empty?
+ api_key = user.api_keys.create! token: SecureRandom.hex
+ puts 'we made a api'
+ else
+ api_key = user.api_keys.first
+ end
+
+ puts "api_key is #{api_key.token_digest}"
+
+ kase.queries.each do |query|
+ Benchmark.measure do
+ url = "http://localhost:3000/api/cases/#{kase.id}/queries/#{query.id}/agent_q"
+ puts url
+ # Create a Faraday connection
+ connection = Faraday.new(url: url) do |faraday|
+ # Set the request headers
+ faraday.headers['Authorization'] = "Bearer #{api_key.token_digest}"
+ faraday.headers['Accept'] = 'application/json'
+ faraday.adapter Faraday.default_adapter
+ end
+
+ # Make the GET request
+ response = connection.get
+ puts 'I did a get'
+ # Parse the response body as JSON
+ data = JSON.parse(response.body)
+
+ puts data
+ end
+ end
+ end
+end
diff --git a/config/initializers/sidekiq.rb b/config/initializers/sidekiq.rb
index dd840e34f..ccf23722b 100644
--- a/config/initializers/sidekiq.rb
+++ b/config/initializers/sidekiq.rb
@@ -2,21 +2,20 @@
# Redis and Sidekiq is used only for sending Google Analytics updates, which is
# primarily used by the app.quepid.com install. This checks if we need Sidekiq.
-#if Rails.application.config.google_analytics_enabled
+# if Rails.application.config.google_analytics_enabled
- sidekiq_config = { url: ENV.fetch('REDIS_URL', nil),
- ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
+sidekiq_config = { url: ENV.fetch('REDIS_URL', nil),
+ ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
- Sidekiq.configure_server do |config|
- config.redis = sidekiq_config
- config.capsule("unsafe") do |cap|
- cap.concurrency = 1
- cap.queues = %w[single]
- end
-
+Sidekiq.configure_server do |config|
+ config.redis = sidekiq_config
+ config.capsule('unsafe') do |cap|
+ cap.concurrency = 1
+ cap.queues = %w[single]
end
+end
- Sidekiq.configure_client do |config|
- config.redis = sidekiq_config
- end
-#end
+Sidekiq.configure_client do |config|
+ config.redis = sidekiq_config
+end
+# end
diff --git a/config/puma.rb b/config/puma.rb
index 339ea631a..4b1eec6b7 100644
--- a/config/puma.rb
+++ b/config/puma.rb
@@ -2,7 +2,8 @@
# Setup taken from https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#adding-puma-to-your-application
-#workers Integer(ENV['WEB_CONCURRENCY'] || 2)
+# With AgentQ doing a call back to ourselves, I think we need to bump this...
+workers Integer(ENV['WEB_CONCURRENCY'] || 2)
#threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
#threads threads_count, threads_count
diff --git a/config/routes.rb b/config/routes.rb
index c1dde0701..3cbfe9918 100755
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -11,7 +11,6 @@
get 'proxy/fetch'
post 'proxy/fetch'
-
mount ActiveStorageDB::Engine => '/active_storage_db'
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
@@ -124,10 +123,9 @@
get 'test_exception' => 'api#test_exception'
scope module: :v1, constraints: ApiConstraint.new(version: 1, default: true) do
-
- get '/agent_q/fetch' => 'agent_q#fetch'
- get '/agent_q/trigger' => 'agent_q#trigger'
-
+ # get '/agent_q/cases/:case_id/queries/:id' => 'agent_q#fetch'
+ # get '/agent_q/trigger' => 'agent_q#trigger'
+
resources :users, only: [ :index, :show, :update ] do
get '/current' => 'current_user#show', on: :collection
end
@@ -148,6 +146,8 @@
# different scenarios.
resources :cases, except: [ :new, :edit ], param: :case_id
resources :cases, only: [] do
+ get '/jobs/trigger' => 'cases/jobs#trigger'
+
# Case Tries
resources :tries, param: :try_number, except: [ :new ] do
post '/duplicate' => 'duplicate_tries#create', as: :duplicate_try
@@ -157,12 +157,13 @@
resources :scorers, only: [ :index, :update ], controller: :case_scorers
# Case Queries
- resources :queries, except: [ :new, :edit, :show ] do
+ resources :queries, except: [ :new, :edit ] do
scope module: :queries do
resource :notes, only: [ :show, :update ]
resource :options, only: [ :show, :update ]
resource :position, only: [ :update ]
resource :ratings, only: [ :update, :destroy ] # not actually a singular resource, doc_id in json payload
+ get 'agent_q' => 'agent_q#fetch'
end
resource :bulk, only: [] do
diff --git a/lib/tasks/sample_data.thor b/lib/tasks/sample_data.thor
index 182fbab47..92c82344d 100644
--- a/lib/tasks/sample_data.thor
+++ b/lib/tasks/sample_data.thor
@@ -228,7 +228,7 @@ class SampleData < Thor
osc.members << realistic_activity_user unless osc.members.include?(realistic_activity_user)
osc.cases << tens_of_queries_case unless osc.members.include?(tens_of_queries_case)
osc.search_endpoints << statedecoded_solr_endpoint unless osc.search_endpoints.include?(statedecoded_solr_endpoint)
-
+
print_step 'End of seeding teams................'
# Books
diff --git a/test/integration/tls_flow_test.rb b/test/integration/tls_flow_test.rb
index 480b6188a..fbb2ef9d2 100644
--- a/test/integration/tls_flow_test.rb
+++ b/test/integration/tls_flow_test.rb
@@ -19,6 +19,7 @@ class TlsFlowTest < ActionDispatch::IntegrationTest
assert try_https.search_endpoint.endpoint_url.starts_with?('https')
# Navigate to a try that is http TLS protocol
+ puts "HEre is the kase id: #{kase.id}"
get case_core_url(id: kase.id, try_number: try_http.try_number)
assert_response :ok
From eacc1d2602137ed9f6ae0548c96fd76bb5034220 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 13:14:09 -0400
Subject: [PATCH 07/19] lint
---
app/assets/javascripts/controllers/queriesStrippedCtrl.js | 2 +-
app/assets/javascripts/services/queriesSvc.js | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/app/assets/javascripts/controllers/queriesStrippedCtrl.js b/app/assets/javascripts/controllers/queriesStrippedCtrl.js
index 5d7ce9500..4bba208a6 100644
--- a/app/assets/javascripts/controllers/queriesStrippedCtrl.js
+++ b/app/assets/javascripts/controllers/queriesStrippedCtrl.js
@@ -37,7 +37,7 @@ angular.module('QuepidApp')
if (!$scope.searching()){
return querySnapshotSvc.createSnapshotPayload('', true, false, queriesSvc.queryArray());
}
- }
+ };
$scope.searching = function() {
return queriesSvc.hasUnscoredQueries();
diff --git a/app/assets/javascripts/services/queriesSvc.js b/app/assets/javascripts/services/queriesSvc.js
index c600371ee..527e57426 100644
--- a/app/assets/javascripts/services/queriesSvc.js
+++ b/app/assets/javascripts/services/queriesSvc.js
@@ -767,7 +767,10 @@ angular.module('QuepidApp')
.then(function(response) {
that.queries = {};
// wrap the single result in an hash with an array.
- let results = {display_order:[response.data.query_id], queries: [response.data]}
+ let results = {
+ display_order:[response.data.query_id],
+ queries: [response.data]
+ };
addQueriesFromResp(results);
From 9e438afbcc58abf90a01edcf155643a4b2703960 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 13:26:25 -0400
Subject: [PATCH 08/19] lint
---
.../api/v1/queries/agent_q_controller.rb | 3 ++-
app/controllers/api/v1/queries_controller.rb | 4 ++--
app/controllers/core_controller.rb | 4 ++--
app/jobs/run_case_job.rb | 23 ++++++++++++-------
app/jobs/run_case_job2.rb | 4 ++++
5 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/app/controllers/api/v1/queries/agent_q_controller.rb b/app/controllers/api/v1/queries/agent_q_controller.rb
index 228e6c702..c8e45646b 100644
--- a/app/controllers/api/v1/queries/agent_q_controller.rb
+++ b/app/controllers/api/v1/queries/agent_q_controller.rb
@@ -21,6 +21,7 @@ class AgentQController < Queries::ApplicationController
before_action :check_query, only: [ :fetch ]
@browser = nil
+ # rubocop:disable Metrics/AbcSize
def fetch
api_key = nil
if @current_user.api_keys.empty?
@@ -88,8 +89,8 @@ def fetch
else
render json: { agentq_error: 'boom', counter: counter }, status: :internal_server_error
end
- # Close the browser
end
+ # rubocop:enable Metrics/AbcSize
end
end
end
diff --git a/app/controllers/api/v1/queries_controller.rb b/app/controllers/api/v1/queries_controller.rb
index 41c1cc87b..052c6ce49 100644
--- a/app/controllers/api/v1/queries_controller.rb
+++ b/app/controllers/api/v1/queries_controller.rb
@@ -39,7 +39,7 @@ def create
if @query.save
@query.insert_at(params[:position].to_i) if params[:position]
# next line I think deals with positioning
- @case.save # Having this line made inserting a new case trigger a bunch of updates which was slow.
+ @case.save # Having this line made inserting a new case trigger a bunch of updates which was slow.
Analytics::Tracker.track_query_created_event current_user, @query
@@ -86,7 +86,7 @@ def destroy
# Make sure queries have the right `arranged_next` and `arranged_at`
# values after the query has been removed
- @case.rearrange_queries # super slow with lots of queires
+ @case.rearrange_queries # super slow with lots of queires
@case.save
head :no_content
diff --git a/app/controllers/core_controller.rb b/app/controllers/core_controller.rb
index 895b8290f..997a23c48 100755
--- a/app/controllers/core_controller.rb
+++ b/app/controllers/core_controller.rb
@@ -6,9 +6,9 @@ class CoreController < ApplicationController
before_action :populate_from_params, except: :new
skip_before_action :check_for_announcement
- #def require_login
+ # def require_login
# @current_user = User.find(3)
- #end
+ # end
# Spiking out can we make an API public?
def authenticate_api!
diff --git a/app/jobs/run_case_job.rb b/app/jobs/run_case_job.rb
index 579263a10..b7e4e6dc1 100644
--- a/app/jobs/run_case_job.rb
+++ b/app/jobs/run_case_job.rb
@@ -4,8 +4,12 @@ class RunCaseJob < ApplicationJob
queue_as :single
sidekiq_options retry: 0
- @@browser = nil
+ @browser = nil
+ # rubocop:disable Metrics/AbcSize
+ # rubocop:disable Metrics/CyclomaticComplexity
+ # rubocop:disable Metrics/MethodLength
+ # rubocop:disable Metrics/PerceivedComplexity
def perform user, kase
api_key = nil
if user.api_keys.empty?
@@ -20,24 +24,23 @@ def perform user, kase
retries = 3
begin
- if @@browser.nil?
+ if @browser.nil?
puts 'creating Ferrum Browser'
# Launch Ferrum browser
- @@browser = Ferrum::Browser.new({
+ @browser = Ferrum::Browser.new({
process_timeout: 5, headless: 'new',
window_size: [ 1280, 800 ],
browser_options: { 'no-sandbox': nil },
timeout: 60,
pending_connection_errors: false,
- js_errors: false,
- browser_options: { 'no-sandbox': nil }
+ js_errors: false
})
end
# @browser.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
- page = @@browser.create_page
+ page = @browser.create_page
page.headers.set({ 'Authorization' => "Bearer #{api_key.token_digest}" })
kase.queries.each do |query|
@@ -92,9 +95,13 @@ def perform user, kase
ensure
# @browser.close if @browser # not yet released
puts 'about to reset browser'
- @@browser.reset
- # @@browser.quit
+ @browser.reset
+ # @browser.quit
# puts "browser quit"
end
end
+ # rubocop:enable Metrics/AbcSize
+ # rubocop:enable Metrics/CyclomaticComplexity
+ # rubocop:enable Metrics/MethodLength
+ # rubocop:enable Metrics/PerceivedComplexity
end
diff --git a/app/jobs/run_case_job2.rb b/app/jobs/run_case_job2.rb
index f46e94ffc..67113575e 100644
--- a/app/jobs/run_case_job2.rb
+++ b/app/jobs/run_case_job2.rb
@@ -4,6 +4,8 @@ class RunCaseJob2 < ApplicationJob
queue_as :single
sidekiq_options retry: 0
+ # rubocop:disable Metrics/MethodLength
+ # rubocop:disable Metrics/AbcSize
def perform user, kase
api_key = nil
if user.api_keys.empty?
@@ -37,4 +39,6 @@ def perform user, kase
end
end
end
+ # rubocop:enable Metrics/MethodLength
+ # rubocop:enable Metrics/AbcSize
end
From 1381cbdc937d2184cd9f9f73a5ccd85c15f6084d Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 13:58:32 -0400
Subject: [PATCH 09/19] relative url
---
app/controllers/api/v1/cases/jobs_controller.rb | 2 +-
app/jobs/run_case_job2.rb | 10 ++++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/app/controllers/api/v1/cases/jobs_controller.rb b/app/controllers/api/v1/cases/jobs_controller.rb
index 192026cef..a0e7196f4 100644
--- a/app/controllers/api/v1/cases/jobs_controller.rb
+++ b/app/controllers/api/v1/cases/jobs_controller.rb
@@ -6,7 +6,7 @@ module Cases
class JobsController < Api::ApiController
def trigger
kase = Case.find(4)
- RunCaseJob2.perform_later kase.owner, kase
+ RunCaseJob2.perform_later kase.owner, kase, root_url
render json: { message: 'scheduled' }, status: :ok
end
diff --git a/app/jobs/run_case_job2.rb b/app/jobs/run_case_job2.rb
index 67113575e..a413b3d50 100644
--- a/app/jobs/run_case_job2.rb
+++ b/app/jobs/run_case_job2.rb
@@ -6,7 +6,7 @@ class RunCaseJob2 < ApplicationJob
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
- def perform user, kase
+ def perform user, kase, root_url
api_key = nil
if user.api_keys.empty?
api_key = user.api_keys.create! token: SecureRandom.hex
@@ -16,10 +16,12 @@ def perform user, kase
end
puts "api_key is #{api_key.token_digest}"
-
+ puts "kase has #{kase.queries.size}"
kase.queries.each do |query|
- Benchmark.measure do
- url = "http://localhost:3000/api/cases/#{kase.id}/queries/#{query.id}/agent_q"
+ Benchmark.measure do
+
+ puts "root url is #{root_url}"
+ url = "#{root_url}api/cases/#{kase.id}/queries/#{query.id}/agent_q"
puts url
# Create a Faraday connection
connection = Faraday.new(url: url) do |faraday|
From 25945a4f681ccce4628601de2cec74bf9752778f Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 13:59:46 -0400
Subject: [PATCH 10/19] lint
---
app/jobs/run_case_job2.rb | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/app/jobs/run_case_job2.rb b/app/jobs/run_case_job2.rb
index a413b3d50..b734679e9 100644
--- a/app/jobs/run_case_job2.rb
+++ b/app/jobs/run_case_job2.rb
@@ -18,8 +18,7 @@ def perform user, kase, root_url
puts "api_key is #{api_key.token_digest}"
puts "kase has #{kase.queries.size}"
kase.queries.each do |query|
- Benchmark.measure do
-
+ Benchmark.measure do
puts "root url is #{root_url}"
url = "#{root_url}api/cases/#{kase.id}/queries/#{query.id}/agent_q"
puts url
From a758c01304104957b098dca34a1eef2018475392 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 14:12:42 -0400
Subject: [PATCH 11/19] oops, had a hardcoded case
---
app/controllers/api/v1/cases/jobs_controller.rb | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/app/controllers/api/v1/cases/jobs_controller.rb b/app/controllers/api/v1/cases/jobs_controller.rb
index a0e7196f4..ff15f384f 100644
--- a/app/controllers/api/v1/cases/jobs_controller.rb
+++ b/app/controllers/api/v1/cases/jobs_controller.rb
@@ -4,9 +4,10 @@ module Api
module V1
module Cases
class JobsController < Api::ApiController
+ before_action :set_case
+ before_action :check_case
def trigger
- kase = Case.find(4)
- RunCaseJob2.perform_later kase.owner, kase, root_url
+ RunCaseJob2.perform_later @current_user, @case, root_url
render json: { message: 'scheduled' }, status: :ok
end
From fad3711eb2b8119c45a95113de46083099bc950f Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 14:19:15 -0400
Subject: [PATCH 12/19] bump to heroku
---
app/controllers/api/v1/cases/jobs_controller.rb | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/controllers/api/v1/cases/jobs_controller.rb b/app/controllers/api/v1/cases/jobs_controller.rb
index ff15f384f..5a2cf410f 100644
--- a/app/controllers/api/v1/cases/jobs_controller.rb
+++ b/app/controllers/api/v1/cases/jobs_controller.rb
@@ -8,7 +8,6 @@ class JobsController < Api::ApiController
before_action :check_case
def trigger
RunCaseJob2.perform_later @current_user, @case, root_url
-
render json: { message: 'scheduled' }, status: :ok
end
end
From 85e2c5b4b5092b51db8d343a76307d08b660e89e Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 14:29:31 -0400
Subject: [PATCH 13/19] disable jupyterlite temporarily
---
lib/tasks/assets.rake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake
index d6860407a..74d72b1bc 100644
--- a/lib/tasks/assets.rake
+++ b/lib/tasks/assets.rake
@@ -26,6 +26,6 @@ namespace :assets do
# Hook into existing assets:precompile task
Rake::Task['assets:precompile'].enhance do
- Rake::Task['assets:jupyterlite'].invoke if Rails.env.production?
+ # Rake::Task['assets:jupyterlite'].invoke if Rails.env.production?
end
end
From 79bd733b13c9da78c82386306d1b78c0d5ac585a Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 14:53:28 -0400
Subject: [PATCH 14/19] remove benchmark
---
app/jobs/run_case_job2.rb | 37 +++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/app/jobs/run_case_job2.rb b/app/jobs/run_case_job2.rb
index b734679e9..8497425cf 100644
--- a/app/jobs/run_case_job2.rb
+++ b/app/jobs/run_case_job2.rb
@@ -18,27 +18,32 @@ def perform user, kase, root_url
puts "api_key is #{api_key.token_digest}"
puts "kase has #{kase.queries.size}"
kase.queries.each do |query|
- Benchmark.measure do
- puts "root url is #{root_url}"
- url = "#{root_url}api/cases/#{kase.id}/queries/#{query.id}/agent_q"
- puts url
- # Create a Faraday connection
- connection = Faraday.new(url: url) do |faraday|
- # Set the request headers
- faraday.headers['Authorization'] = "Bearer #{api_key.token_digest}"
- faraday.headers['Accept'] = 'application/json'
- faraday.adapter Faraday.default_adapter
- end
+ puts "root url is #{root_url}"
+ url = "#{root_url}api/cases/#{kase.id}/queries/#{query.id}/agent_q"
+ puts url
+ # Create a Faraday connection
+ connection = Faraday.new(url: url) do |faraday|
+ # Set the request headers
+ faraday.headers['Authorization'] = "Bearer #{api_key.token_digest}"
+ faraday.headers['Accept'] = 'application/json'
+ faraday.adapter Faraday.default_adapter
+ end
- # Make the GET request
- response = connection.get
- puts 'I did a get'
- # Parse the response body as JSON
+ # Make the GET request
+ response = connection.get
+ puts 'I did a get'
+
+ if response.status == :ok
+ # Parse the response body as JSON
data = JSON.parse(response.body)
puts data
- end
+ else
+ puts "Didn't get okay response. #{response.status}"
+ puts "Response.body: #{response.body}"
+
end
+
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
From 0be71aa009d9a4d7e1494c646c639512cf9eae84 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 16:20:47 -0400
Subject: [PATCH 15/19] need this dependency...
---
app/assets/javascripts/core_stripped.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/assets/javascripts/core_stripped.js b/app/assets/javascripts/core_stripped.js
index 80fd30a3c..f06f448f6 100644
--- a/app/assets/javascripts/core_stripped.js
+++ b/app/assets/javascripts/core_stripped.js
@@ -27,6 +27,7 @@
//= require angular-rails-templates
//= require splainer-search/splainer-search
//= require angular-flash/dist/angular-flash
+//= require urijs/src/URI
//= require utilitiesModule
//= require app_stripped
//= require routes
From 0b3ee40a35a0f3e1ab7df52ef01541e581d239fe Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 16:22:00 -0400
Subject: [PATCH 16/19] lint
---
app/jobs/run_case_job2.rb | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/app/jobs/run_case_job2.rb b/app/jobs/run_case_job2.rb
index 8497425cf..e1b5388b6 100644
--- a/app/jobs/run_case_job2.rb
+++ b/app/jobs/run_case_job2.rb
@@ -19,6 +19,8 @@ def perform user, kase, root_url
puts "kase has #{kase.queries.size}"
kase.queries.each do |query|
puts "root url is #{root_url}"
+ puts 'changing to https://localhost'
+ root_url = 'https://localhost/'
url = "#{root_url}api/cases/#{kase.id}/queries/#{query.id}/agent_q"
puts url
# Create a Faraday connection
@@ -27,23 +29,24 @@ def perform user, kase, root_url
faraday.headers['Authorization'] = "Bearer #{api_key.token_digest}"
faraday.headers['Accept'] = 'application/json'
faraday.adapter Faraday.default_adapter
+ faraday.ssl.verify = false # Disable SSL certificate validation
end
# Make the GET request
response = connection.get
puts 'I did a get'
-
- if response.status == :ok
- # Parse the response body as JSON
+
+ if :ok == response.status
+ # Parse the response body as JSON
data = JSON.parse(response.body)
puts data
- else
- puts "Didn't get okay response. #{response.status}"
- puts "Response.body: #{response.body}"
-
+ else
+ puts "Didn't get okay response. #{response.status}"
+ puts "Response.body: #{response.body}"
+
+ end
end
-
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
From e8a4e6a30ceb9301a49f378d478de12d5e2da84b Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 16:34:47 -0400
Subject: [PATCH 17/19] bit of messaging
---
app/assets/javascripts/controllers/strippedCtrl.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/assets/javascripts/controllers/strippedCtrl.js b/app/assets/javascripts/controllers/strippedCtrl.js
index 529a19c67..0d125e386 100644
--- a/app/assets/javascripts/controllers/strippedCtrl.js
+++ b/app/assets/javascripts/controllers/strippedCtrl.js
@@ -14,7 +14,7 @@ angular.module('QuepidApp')
caseSvc, settingsSvc, caseTryNavSvc,
queryViewSvc, queriesSvc, docCacheSvc
) {
- $log.debug('NEW MAIN CTRL STRIPPED VERSION');
+ $log.debug('NEW STRIPPED MAIN CTRLr');
var caseNo = parseInt($routeParams.caseNo, 10);
var tryNo = parseInt($routeParams.tryNo, 10);
From 90ba9dd5f7716d175b8529aab887b864cc523822 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 16:40:01 -0400
Subject: [PATCH 18/19] back out debugging
---
app/jobs/run_case_job2.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/app/jobs/run_case_job2.rb b/app/jobs/run_case_job2.rb
index e1b5388b6..eb7502d7f 100644
--- a/app/jobs/run_case_job2.rb
+++ b/app/jobs/run_case_job2.rb
@@ -19,8 +19,8 @@ def perform user, kase, root_url
puts "kase has #{kase.queries.size}"
kase.queries.each do |query|
puts "root url is #{root_url}"
- puts 'changing to https://localhost'
- root_url = 'https://localhost/'
+ # puts 'changing to https://localhost'
+ # root_url = 'https://localhost/'
url = "#{root_url}api/cases/#{kase.id}/queries/#{query.id}/agent_q"
puts url
# Create a Faraday connection
From 000ed91bdf76b48278a8b91c5587860f415d9828 Mon Sep 17 00:00:00 2001
From: Eric Pugh
Date: Wed, 17 Apr 2024 17:33:01 -0400
Subject: [PATCH 19/19] fix logic
---
app/jobs/run_case_job2.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/jobs/run_case_job2.rb b/app/jobs/run_case_job2.rb
index eb7502d7f..acc2e5aa5 100644
--- a/app/jobs/run_case_job2.rb
+++ b/app/jobs/run_case_job2.rb
@@ -36,7 +36,7 @@ def perform user, kase, root_url
response = connection.get
puts 'I did a get'
- if :ok == response.status
+ if response.success?
# Parse the response body as JSON
data = JSON.parse(response.body)