diff --git a/app/controllers/admin/research/researchers_controller.rb b/app/controllers/admin/research/researchers_controller.rb index 81c0ad21868b26b2fefacc2519c59fee73a4afee..49b966e945b1bc1679e3a0000c5fbdc64308fc77 100644 --- a/app/controllers/admin/research/researchers_controller.rb +++ b/app/controllers/admin/research/researchers_controller.rb @@ -22,7 +22,12 @@ class Admin::Research::ResearchersController < Admin::Research::ApplicationContr end def sync_with_hal - @researcher.import_research_hal_publications! + begin + Research::Hal.pause_git_sync + @researcher.import_research_hal_publications! + ensure + Research::Hal.unpause_git_sync + end redirect_to admin_research_researcher_path(@researcher) end diff --git a/app/models/research/hal.rb b/app/models/research/hal.rb index 775b8dc4e8f3d0df212e11b5e910a36213094689..0554fa97527f2d37fab0b9d25a6c5be18cd2d233 100644 --- a/app/models/research/hal.rb +++ b/app/models/research/hal.rb @@ -8,15 +8,34 @@ module Research::Hal def self.update_from_api! begin - Research::Hal::Publication.skip_callback :save, :after, :connect_and_sync_direct_sources + pause_git_sync Research::Hal::Author.find_each do |author| author.import_research_hal_publications! end ensure - Research::Hal::Publication.set_callback :save, :after, :connect_and_sync_direct_sources + unpause_git_sync end end + def self.pause_git_sync + Research::Hal::Publication.skip_callback :save, :after, :connect_and_sync_direct_sources + end + + def self.unpause_git_sync + Research::Hal::Publication.set_callback :save, :after, :connect_and_sync_direct_sources + end + + def self.clear_queue! + ids = [] + Delayed::Job.find_each do |job| + if job.payload_object.method_name == :sync_indirect_object_with_git_without_delay && + job.payload_object.args.first.is_a?(Research::Hal::Publication) + ids << job.id + end + end + Delayed::Job.where(id: ids).destroy_all + end + def self.parts [ [Research::Hal::Publication, :admin_research_hal_publications_path],