Class: ChainedJob::CleanUpQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/chained_job/clean_up_queue.rb

Constant Summary collapse

TRIM_STEP_SIZE =
1_000

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_arguments_key) ⇒ CleanUpQueue

Returns a new instance of CleanUpQueue.



15
16
17
# File 'lib/chained_job/clean_up_queue.rb', line 15

def initialize(job_arguments_key)
  @job_arguments_key = job_arguments_key
end

Instance Attribute Details

#job_arguments_keyObject (readonly)

Returns the value of attribute job_arguments_key.



13
14
15
# File 'lib/chained_job/clean_up_queue.rb', line 13

def job_arguments_key
  @job_arguments_key
end

Class Method Details

.run(job_arguments_key) ⇒ Object



7
8
9
# File 'lib/chained_job/clean_up_queue.rb', line 7

def self.run(job_arguments_key)
  new(job_arguments_key).run
end

Instance Method Details

#runObject

rubocop:disable Metrics/AbcSize



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chained_job/clean_up_queue.rb', line 20

def run
  loop do
    tag = ChainedJob.redis.call(:spop, tag_list)

    break unless tag

    redis_key = Helpers.redis_key(job_key, tag)
    size = ChainedJob.redis.call(:llen, redis_key)
    (size / TRIM_STEP_SIZE).times { ChainedJob.redis.call(:ltrim, redis_key, 0, -TRIM_STEP_SIZE) }

    ChainedJob.redis.call(:del, redis_key)
  end
end