-
Notifications
You must be signed in to change notification settings - Fork 2
Adding NBP push connector #1452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
|
MrSerth marked this conversation as resolved.
MrSerth marked this conversation as resolved.
|
This file contains hidden or 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 | ||
|
MrSerth marked this conversation as resolved.
|
||
| 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 hidden or 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 |
|
MrSerth marked this conversation as resolved.
MrSerth marked this conversation as resolved.
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||
|
Mathis-Z marked this conversation as resolved.
|
||
| super | ||
| self.tags = ALLOW_LIST['tags'] | ||
| self.attributes = ALLOW_LIST['attributes'] | ||
| end | ||
| end | ||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.