Class: Beehive::Client
- Inherits:
-
Object
- Object
- Beehive::Client
- Defined in:
- lib/beehive/client.rb
Overview
The client class that can be used to add and manage jobs in the queue.
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Instance of the class “Redis”.
Instance Method Summary collapse
-
#disconnect ⇒ Object
Closes the Redis connection.
-
#get(job) ⇒ Array
Retrieves the last job and removes it from the storage.
-
#initialize(options = {}) ⇒ Client
constructor
Creates a new instance of the client and sends the specified options to Redis.
-
#queue(job, params = {}) ⇒ Object
Queues a given job in the storage.
Constructor Details
#initialize(options = {}) ⇒ Client
Creates a new instance of the client and sends the specified options to Redis.
Redis#initialize for more information.
20 21 22 |
# File 'lib/beehive/client.rb', line 20 def initialize( = {}) @connection = ::Redis.new() end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Instance of the class “Redis”
10 11 12 |
# File 'lib/beehive/client.rb', line 10 def connection @connection end |
Instance Method Details
#disconnect ⇒ Object
Closes the Redis connection.
66 67 68 |
# File 'lib/beehive/client.rb', line 66 def disconnect @connection.quit end |
#get(job) ⇒ Array
Retrieves the last job and removes it from the storage.
51 52 53 54 55 56 57 58 |
# File 'lib/beehive/client.rb', line 51 def get(job) job = "beehive.jobs.#{job}" job = @connection.lpop(job) if !job.nil? return JSON.load(job) end end |
#queue(job, params = {}) ⇒ Object
Queues a given job in the storage.
36 37 38 39 40 41 |
# File 'lib/beehive/client.rb', line 36 def queue(job, params = {}) job = "beehive.jobs.#{job}" params = JSON.dump(params) @connection.rpush(job, params) end |