Class: Bushpig::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bushpig/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool, &callback) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
# File 'lib/bushpig/client.rb', line 7

def initialize(pool, &callback)
  @pool = pool
  @default_ttl = nil
  @callback = callback
end

Instance Attribute Details

#default_ttlObject

Returns the value of attribute default_ttl.



5
6
7
# File 'lib/bushpig/client.rb', line 5

def default_ttl
  @default_ttl
end

Instance Method Details

#default_scoreObject



17
18
19
# File 'lib/bushpig/client.rb', line 17

def default_score
  Time.now.to_f
end

#redis_poolObject



13
14
15
# File 'lib/bushpig/client.rb', line 13

def redis_pool
  @pool
end

#submit(queue, job, score: default_score, ttl: default_ttl) ⇒ Object



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

def submit(queue, job, score: default_score, ttl: default_ttl)
  new = if Bushpig.testing
          job.handle
          true
        else
          redis_pool.with do |conn|
            conn.set(Bushpig.job_key(job.job_key), job.job_payload, ex: ttl)
            conn.zadd(Bushpig.queue_key(queue), score, job.job_key)
          end
        end
  @callback&.call(job, new)
end