Module: SidekiqUniqueJobs::Scripts

Extended by:
SingleForwardable
Includes:
Overrides
Defined in:
lib/sidekiq_unique_jobs/scripts.rb,
lib/sidekiq_unique_jobs/testing.rb,
lib/sidekiq_unique_jobs/scripts/acquire_lock.rb,
lib/sidekiq_unique_jobs/scripts/release_lock.rb

Defined Under Namespace

Modules: Overrides Classes: AcquireLock, ReleaseLock

Class Method Summary collapse

Methods included from Overrides

included

Class Method Details

.call(file_name, redis_pool, options = {}) ⇒ Object


27
28
29
30
31
# File 'lib/sidekiq_unique_jobs/scripts.rb', line 27

def call(file_name, redis_pool, options = {})
  internal_call(file_name, redis_pool, options)
rescue Redis::CommandError => ex
  handle_error(ex, file_name, redis_pool, options)
end

.handle_error(exception, file_name, redis_pool, options = {}) ⇒ Object


40
41
42
43
44
45
46
47
# File 'lib/sidekiq_unique_jobs/scripts.rb', line 40

def handle_error(exception, file_name, redis_pool, options = {})
  if exception.message == 'NOSCRIPT No matching script. Please use EVAL.' # rubocop:disable Style/GuardClause
    SCRIPT_SHAS.delete(file_name)
    call(file_name, redis_pool, options)
  else
    raise ScriptError, "Problem compiling #{file_name}. Invalid LUA syntax?"
  end
end

.internal_call(file_name, redis_pool, options = {}) ⇒ Object


33
34
35
36
37
38
# File 'lib/sidekiq_unique_jobs/scripts.rb', line 33

def internal_call(file_name, redis_pool, options = {})
  connection(redis_pool) do |conn|
    SCRIPT_SHAS[file_name] = conn.script(:load, script_source(file_name)) if SCRIPT_SHAS[file_name].nil?
    conn.evalsha(SCRIPT_SHAS[file_name], options)
  end
end

.script_path(file_name) ⇒ Object


53
54
55
# File 'lib/sidekiq_unique_jobs/scripts.rb', line 53

def script_path(file_name)
  LUA_PATHNAME.join("#{file_name}.lua")
end

.script_source(file_name) ⇒ Object


49
50
51
# File 'lib/sidekiq_unique_jobs/scripts.rb', line 49

def script_source(file_name)
  script_path(file_name).read
end