Class: Plines::JobBatchList

Inherits:
Struct
  • Object
show all
Includes:
RedisObjectsHelpers
Defined in:
lib/plines/job_batch_list.rb

Overview

Represents a list of job batches that are grouped by some common trait (such as a user id).

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RedisObjectsHelpers

#declared_redis_object_keys, included, #key_prefix, #new_redis_object

Constructor Details

#initialize(pipeline, key) ⇒ JobBatchList

Returns a new instance of JobBatchList.



12
13
14
15
16
# File 'lib/plines/job_batch_list.rb', line 12

def initialize(pipeline, key)
  super(pipeline, key)
  @qless = pipeline.configuration.qless_client_for(key)
  @redis = @qless.redis
end

Instance Attribute Details

#keyObject Also known as: id

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



6
7
8
# File 'lib/plines/job_batch_list.rb', line 6

def key
  @key
end

#pipelineObject

Returns the value of attribute pipeline

Returns:

  • (Object)

    the current value of pipeline



6
7
8
# File 'lib/plines/job_batch_list.rb', line 6

def pipeline
  @pipeline
end

#qlessObject (readonly)

Returns the value of attribute qless.



10
11
12
# File 'lib/plines/job_batch_list.rb', line 10

def qless
  @qless
end

#redisObject (readonly)

Returns the value of attribute redis.



10
11
12
# File 'lib/plines/job_batch_list.rb', line 10

def redis
  @redis
end

Instance Method Details

#all_with_external_dependency_timeout(dep_name) ⇒ Object



42
43
44
45
46
# File 'lib/plines/job_batch_list.rb', line 42

def all_with_external_dependency_timeout(dep_name)
  each.select do |batch|
    batch.timed_out_external_deps.include?(dep_name)
  end
end

#create_new_batch(batch_data, options = {}, &blk) ⇒ Object



24
25
26
27
28
# File 'lib/plines/job_batch_list.rb', line 24

def create_new_batch(batch_data, options = {}, &blk)
  JobBatch.create(qless, pipeline,
                  batch_id_for(last_batch_num.increment),
                  batch_data, options, &blk)
end

#each(&block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/plines/job_batch_list.rb', line 30

def each(&block)
  return enum_for(:each) unless block_given?

  1.upto(last_batch_num.value) do |num|
    begin
      yield JobBatch.find(qless, pipeline, batch_id_for(num))
    rescue JobBatch::CannotFindExistingJobBatchError
      # We can't yield a batch we can't find!
    end
  end
end

#most_recent_batchObject



18
19
20
21
22
# File 'lib/plines/job_batch_list.rb', line 18

def most_recent_batch
  batch_num = last_batch_num.value
  return nil if batch_num.zero?
  JobBatch.find(qless, pipeline, batch_id_for(batch_num))
end