Class: SimpleMutex::SidekiqSupport::JobWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_mutex/sidekiq_support/job_wrapper.rb

Constant Summary collapse

DEFAULT_EXPIRES_IN =

5 hours

5 * 60 * 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, params: [], lock_key: nil, lock_with_params: false, expires_in: DEFAULT_EXPIRES_IN) ⇒ JobWrapper

Returns a new instance of JobWrapper.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/simple_mutex/sidekiq_support/job_wrapper.rb', line 10

def initialize(job,
               params:           [],
               lock_key:         nil,
               lock_with_params: false,
               expires_in:       DEFAULT_EXPIRES_IN)
  self.job              = job
  self.params           = params

  self.lock_key         = lock_key
  self.lock_with_params = lock_with_params
  self.expires_in       = expires_in
end

Instance Attribute Details

#expires_inObject

Returns the value of attribute expires_in.



6
7
8
# File 'lib/simple_mutex/sidekiq_support/job_wrapper.rb', line 6

def expires_in
  @expires_in
end

#jobObject

Returns the value of attribute job.



6
7
8
# File 'lib/simple_mutex/sidekiq_support/job_wrapper.rb', line 6

def job
  @job
end

#lock_keyObject

Returns the value of attribute lock_key.



6
7
8
# File 'lib/simple_mutex/sidekiq_support/job_wrapper.rb', line 6

def lock_key
  @lock_key
end

#lock_with_paramsObject

Returns the value of attribute lock_with_params.



6
7
8
# File 'lib/simple_mutex/sidekiq_support/job_wrapper.rb', line 6

def lock_with_params
  @lock_with_params
end

#paramsObject

Returns the value of attribute params.



6
7
8
# File 'lib/simple_mutex/sidekiq_support/job_wrapper.rb', line 6

def params
  @params
end

Instance Method Details

#with_redlock(&block) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/simple_mutex/sidekiq_support/job_wrapper.rb', line 23

def with_redlock(&block)
  ::SimpleMutex::Mutex.with_lock(
    lock_key || generate_lock_key,
    expires_in: expires_in,
    payload:    generate_payload,
    &block
  )
end