From 8b8e812dd9062d7183584e89475b68875d50bfa5 Mon Sep 17 00:00:00 2001 From: Ben Pennell Date: Fri, 15 Nov 2024 10:10:39 -0500 Subject: [PATCH] Explicitly add redlock dependency. Require redlock --- Gemfile | 1 + Gemfile.lock | 1 + .../lib/hydra/derivatives/processors/document_override.rb | 6 +++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 997df08c3..babacfae5 100644 --- a/Gemfile +++ b/Gemfile @@ -56,6 +56,7 @@ gem 'rails', '~> 6.0' gem 'rdf', git: 'https://github.com/ruby-rdf/rdf.git', branch: '3.2.11-patch' # Use Redis adapter to run Action Cable in production gem 'redis', '~> 4.5.0' +gem 'redlock' # version determined by hyrax gem 'riiif', '~> 2.5.0' gem 'roo', '~>2.9.0' gem 'rsolr', '~> 2.5.0' diff --git a/Gemfile.lock b/Gemfile.lock index 5b2b85675..bf1cd1c48 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1130,6 +1130,7 @@ DEPENDENCIES rails (~> 6.0) rdf! redis (~> 4.5.0) + redlock riiif (~> 2.5.0) roo (~> 2.9.0) rsolr (~> 2.5.0) diff --git a/app/overrides/lib/hydra/derivatives/processors/document_override.rb b/app/overrides/lib/hydra/derivatives/processors/document_override.rb index 2fb4dff08..b4101071e 100644 --- a/app/overrides/lib/hydra/derivatives/processors/document_override.rb +++ b/app/overrides/lib/hydra/derivatives/processors/document_override.rb @@ -1,12 +1,15 @@ # frozen_string_literal: true # [hyc-override] https://github.com/samvera/hydra-derivatives/blob/v3.8.0/lib/hydra/derivatives/processors/document.rb +require 'redlock' + class SofficeTimeoutError < StandardError; end Hydra::Derivatives::Processors::Document.class_eval do + # [hyc-override] Use Redlock to manage soffice process lock LOCK_KEY = "soffice:document_conversion" LOCK_TIMEOUT = 6 * 60 * 1000 JOB_TIMEOUT_SECONDS = 30 - LOCK_MANAGER = Redlock::Client.new([ENV['REDIS_URL']]) + LOCK_MANAGER = Redlock::Client.new([Redis.current]) # [hyc-override] Trigger kill if soffice process takes too long, and throw a non-retry error if that happens def self.encode(path, format, outdir, timeout = JOB_TIMEOUT_SECONDS) @@ -37,6 +40,7 @@ def self.encode(path, format, outdir, timeout = JOB_TIMEOUT_SECONDS) # TODO: file_suffix and options are passed from ShellBasedProcessor.process but are not needed. # A refactor could simplify this. def encode_file(_file_suffix, _options = {}) + # [hyc-override] Use Redlock to manage soffice process lock, since only one soffice process can run at a time LOCK_MANAGER.lock(LOCK_KEY, LOCK_TIMEOUT) do |locked| if locked convert_to_format