Class: Bluecollar::Client

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.configurationObject (readonly)

Returns the value of attribute configuration.



8
9
10
# File 'lib/bluecollar-client/client.rb', line 8

def configuration
  @configuration
end

.instanceObject (readonly)

Returns the value of attribute instance.



8
9
10
# File 'lib/bluecollar-client/client.rb', line 8

def instance
  @instance
end

.loggerObject (readonly)

Returns the value of attribute logger.



8
9
10
# File 'lib/bluecollar-client/client.rb', line 8

def logger
  @logger
end

Instance Attribute Details

#redis_dbObject

Returns the value of attribute redis_db.



4
5
6
# File 'lib/bluecollar-client/client.rb', line 4

def redis_db
  @redis_db
end

#redis_hostnameObject

Returns the value of attribute redis_hostname.



4
5
6
# File 'lib/bluecollar-client/client.rb', line 4

def redis_hostname
  @redis_hostname
end

#redis_key_prefixObject

Returns the value of attribute redis_key_prefix.



4
5
6
# File 'lib/bluecollar-client/client.rb', line 4

def redis_key_prefix
  @redis_key_prefix
end

#redis_portObject

Returns the value of attribute redis_port.



4
5
6
# File 'lib/bluecollar-client/client.rb', line 4

def redis_port
  @redis_port
end

#redis_timeoutObject

Returns the value of attribute redis_timeout.



4
5
6
# File 'lib/bluecollar-client/client.rb', line 4

def redis_timeout
  @redis_timeout
end

Class Method Details

.configure(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bluecollar-client/client.rb', line 10

def configure(options = {})
  @instance = nil

  @logger = options[:logger] || Logger.new("/dev/null")

  @configuration = {}
  @configuration[:redis_key_prefix] = options[:redis_key_prefix] || "bluecollar"
  @configuration[:redis_hostname] = options[:redis_hostname] || "127.0.0.1"
  @configuration[:redis_port] = (options[:redis_port] || 6379).to_i
  @configuration[:redis_db] = options[:redis_db].to_i
  @configuration[:redis_timeout] = (options[:redis_timeout] || 5000).to_i
end

Instance Method Details

#async_job_for(worker_name, args) ⇒ Object



28
29
30
31
32
33
# File 'lib/bluecollar-client/client.rb', line 28

def async_job_for(worker_name, args)
  redis_connection.lpush processing_queue, redis_payload(worker_name, args)
rescue Redis::BaseError => e
  Bluecollar::Client.logger.warn("Error while adding #{worker_name}: #{args.inspect} to queue.\n#{e}:#{e.message}\nBacktrace:\n\t#{e.backtrace.join("\n\t")}")
  raise Bluecollar::ClientError.new("Error while adding #{worker_name}: #{args.inspect} to queue.\n#{e}:#{e.message}\nBacktrace:\n\t#{e.backtrace.join("\n\t")}")
end