-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into add_gpt_api_key_per_user
- Loading branch information
Showing
33 changed files
with
1,624 additions
and
510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class ApplicationJob < ActiveJob::Base | ||
include ActiveRecordLogging | ||
|
||
# Automatically retry jobs that encountered a deadlock | ||
retry_on ActiveRecord::Deadlocked | ||
|
||
# Most jobs are safe to ignore if the underlying records are no longer available | ||
discard_on ActiveJob::DeserializationError | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
# This module is used to log ActiveRecord queries performed in jobs. | ||
module ActiveRecordLogging | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
around_perform do |_job, block| | ||
# With our current Solid Queue setup, there is a difference between both logger: | ||
# - *ActiveRecord::Base.logger*: This logger is used for SQL queries and, normally, writes to the log file only. | ||
# - *Rails.logger*: The regular logger, which writes to the log file and the console. | ||
# For the duration of the job, we want to write the SQL queries to the Rails logger, so they show up in the console. | ||
# See config/solid_queue_logging.rb for more information. | ||
previous_logger = ActiveRecord::Base.logger | ||
ActiveRecord::Base.logger = Rails.logger | ||
block.call | ||
ActiveRecord::Base.logger = previous_logger | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class NbpSyncAllJob < ApplicationJob | ||
def perform | ||
uuids = Set[] | ||
|
||
# First, add all uploaded UUIDs. | ||
# This allows us to delete the ones that are still present remote but no longer in the local database. | ||
Nbp::PushConnector.instance.process_uploaded_task_uuids do |uuid| | ||
uuids.add(uuid) | ||
end | ||
|
||
# Then, add all local UUIDs. | ||
# This allows us to upload tasks missing remote (and remove private tasks not yet removed). | ||
Task.select(:id, :uuid).find_each {|task| uuids.add(task.uuid) } | ||
|
||
# Finally, schedule a full sync for each UUID identified. | ||
uuids.each do |uuid| | ||
NbpSyncJob.perform_later uuid | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
class NbpSyncJob < ApplicationJob | ||
retry_on Faraday::Error, Nbp::PushConnector::ServerError, wait: :polynomially_longer, attempts: 5 | ||
|
||
def perform(uuid) | ||
task = Task.find_by(uuid:) | ||
|
||
if task.present? && task.access_level_public? | ||
builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') {|xml| LomService::ExportLom.call(task:, xml:) } | ||
Nbp::PushConnector.instance.push_lom!(builder.to_xml) | ||
Rails.logger.debug { "Task ##{task.id} \"#{task}\" pushed to NBP" } | ||
else | ||
Nbp::PushConnector.instance.delete_task!(uuid) | ||
Rails.logger.debug { "Task with UUID #{uuid} deleted from NBP" } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module LomService | ||
class NbpScrubber < Rails::HTML::PermitScrubber | ||
ALLOW_LIST = YAML.safe_load_file(Rails.root.join('app/services/lom_service/nbp_scrubber_allow_list.yml')) | ||
|
||
def initialize | ||
super | ||
self.tags = ALLOW_LIST['tags'] | ||
self.attributes = ALLOW_LIST['attributes'] | ||
end | ||
end | ||
end |
Oops, something went wrong.