Skip to content

Commit

Permalink
Explicitly add redlock dependency. Require redlock
Browse files Browse the repository at this point in the history
  • Loading branch information
bbpennel committed Nov 15, 2024
1 parent f46d938 commit 8b8e812
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8b8e812

Please sign in to comment.