-
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.
- Loading branch information
Showing
28 changed files
with
1,095 additions
and
6 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
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
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 |
---|---|---|
|
@@ -20,6 +20,17 @@ omniauth: | |
private_key: ~ | ||
oai_pmh: | ||
admin_mail: [email protected] | ||
nbp: | ||
push_connector: | ||
enable: true | ||
client_id: testing_client_id | ||
client_secret: testing_client_secret | ||
token_path: 'https://test.provider/token' | ||
api_host: 'https://test.api.host' | ||
source: | ||
organization: test_organization | ||
name: CodeHarbor | ||
slug: CoHaP2 | ||
open_ai: | ||
access_token: ~ # Add a valid API key from https://platform.openai.com/api-keys | ||
model: gpt-4o-mini |
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,25 @@ | ||
default: &default | ||
dispatchers: | ||
- polling_interval: 1 | ||
batch_size: 500 | ||
workers: | ||
- queues: "*" | ||
threads: 3 | ||
processes: 1 | ||
polling_interval: 0.1 | ||
|
||
development: | ||
<<: *default | ||
|
||
test: | ||
<<: *default | ||
|
||
production: | ||
<<: *default | ||
dispatchers: | ||
- polling_interval: 1 | ||
batch_size: 500 | ||
recurring_tasks: | ||
nbp_sync_all_job: | ||
class: NbpSyncAllJob | ||
schedule: "0 3 * * *" |
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,39 @@ | ||
# frozen_string_literal: true | ||
|
||
# This file must be loaded before other initializers due to the logging configuration. | ||
Rails.application.configure do | ||
# On shutdown, jobs Solid Queue will wait the specified timeout before forcefully shutting down. | ||
# Any job not finished by then will be picked up again after a restart. | ||
config.solid_queue.shutdown_timeout = 10.seconds | ||
# Remove *successful* jobs from the database after 30 days | ||
config.solid_queue.clear_finished_jobs_after = 30.days | ||
config.solid_queue.supervisor_pidfile = Rails.root.join('tmp/pids/solid_queue_supervisor.pid') | ||
|
||
# For Solid Queue, we want to hide regular SQL queries from the console, but still log them to a separate file. | ||
# For the normal webserver, this dedicated setup is neither needed nor desired. | ||
next unless Rake.application.top_level_tasks.to_s.include?('solid_queue:') | ||
|
||
# Specify that all logs should be written to the specified log file | ||
file_name = "#{Rails.env}.solid_queue.log" | ||
config.paths.add 'log', with: "log/#{file_name}" | ||
|
||
# Send all logs regarding SQL queries to the log file. | ||
# This will include all queries performed by Solid Queue including periodic job checks. | ||
log_file = ActiveSupport::Logger.new(Rails.root.join('log', file_name)) | ||
config.active_record.logger = ActiveSupport::BroadcastLogger.new(log_file) | ||
|
||
config.after_initialize do | ||
# Create a new logger that will write to the console | ||
console = ActiveSupport::Logger.new($stdout) | ||
console.level = Rails.logger.level | ||
# Enable this line to have the same log format as Rails.logger | ||
# It will include the job name, the job ID for each line | ||
# console.formatter = Rails.logger.formatter | ||
|
||
ActiveSupport.on_load :solid_queue_record do | ||
# Once SolidQueue is loaded, we can broadcast its logs to the console, too. | ||
# Due to the initialization order, this will effectively start logging once SolidQueue is about to start. | ||
Rails.logger.broadcast_to console | ||
end | ||
end | ||
end |
Oops, something went wrong.