Class: Hooker::Client
- Inherits:
-
Object
- Object
- Hooker::Client
- Defined in:
- lib/hooker/client.rb,
lib/hooker/client/version.rb
Constant Summary collapse
- NEW_JOBS_LIST =
"hooker:jobs"
- FAILURES_LIST =
"hooker:failures"
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
Instance Method Summary collapse
-
#enqueue(url, headers, subscription, payload) ⇒ Object
TODO: Use shared secret to calculate HMAC and add to headers hash.
- #get_next_failure ⇒ Object
-
#initialize(redis) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(redis) ⇒ Client
Returns a new instance of Client.
13 14 15 |
# File 'lib/hooker/client.rb', line 13 def initialize(redis) @redis = redis end |
Instance Attribute Details
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
12 13 14 |
# File 'lib/hooker/client.rb', line 12 def redis @redis end |
Instance Method Details
#enqueue(url, headers, subscription, payload) ⇒ Object
TODO: Use shared secret to calculate HMAC and add to headers hash
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hooker/client.rb', line 18 def enqueue(url, headers, subscription, payload) stringy_headers = {}.tap do |h| headers.each { |k, v| h[k.to_s] = v.to_s } end uuid = SecureRandom.uuid _, queue_length = redis.pipelined do redis.hmset(job_key(uuid), "url", url, "headers", stringy_headers.to_json, "subscription", subscription, "payload", payload) redis.lpush(NEW_JOBS_LIST, uuid) end queue_length end |
#get_next_failure ⇒ Object
31 32 33 34 |
# File 'lib/hooker/client.rb', line 31 def get_next_failure # block indefinitely waiting for the next failure. redis.blpop(FAILURES_LIST, 0) end |