Class: BigWig::Push
- Inherits:
-
Object
- Object
- BigWig::Push
- Defined in:
- lib/bigwig/push.rb
Overview
pushes a message onto the queue USAGE:
push = BigWig::Push.new :config => '/path/to/config/file', :timeout => 5
By default, it uses bigwig.yml in the current directory and a timeout of 5 seconds The configuration file is expected to have the same structure as the BigWig daemon’s file (without the plugins folder)
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.load_options_from(command_line) ⇒ Object
Helper method so that calling scripts don’t need to parse the Push parameters themselves.
Instance Method Summary collapse
-
#initialize(overrides = {}) ⇒ Push
constructor
Create a new BigWig::Push Options: :config => ‘/path/to/config/file’ :timeout => 5.
-
#message(method, data = {}, task_id = nil, queue = :default) ⇒ Object
Push a message on to the queue, passing in a message name, plus an optional data hash, an optional task id and an optional queue name.
Constructor Details
#initialize(overrides = {}) ⇒ Push
Create a new BigWig::Push Options:
:config => '/path/to/config/file'
:timeout => 5
23 24 25 26 27 28 |
# File 'lib/bigwig/push.rb', line 23 def initialize(overrides = {}) @options = { :config => File.('./bigwig.yml'), :timeout => 5 }.merge(overrides) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/bigwig/push.rb', line 15 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/bigwig/push.rb', line 16 def @options end |
Class Method Details
.load_options_from(command_line) ⇒ Object
Helper method so that calling scripts don’t need to parse the Push parameters themselves
USAGE:
= BigWig::Push. ARGV
BigWig::Push.new(). 'whatever'
If this is being called from a wrapper script (such as bin/bigwig-push) that needs its own parameters you can pass a block to append your own details
= BigWig::Push.(ARGV) do | parser, |
parser.on('--xxx', 'Push it good') do
[:push_it_good] = :push_it_real_good
end
end
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/bigwig/push.rb', line 69 def self. command_line = {} parser = OptionParser.new do | parser | parser. = "Usage: #{File.basename($0)} [options]" parser.on('-h', '--help', 'Show this message') do puts parser exit 2 end parser.on('-c', '--config=file', 'Path to the config file; if not supplied then bigwig looks for bigwig.yml in the current folder') do |conf| [:config] = conf end parser.on('-t', '--timeout=value', 'Timeout value in seconds') do | conf | [:timeout] = conf.to_i end yield(parser, ) if block_given? end parser.parse!(command_line) return end |
Instance Method Details
#message(method, data = {}, task_id = nil, queue = :default) ⇒ Object
Push a message on to the queue, passing in a message name, plus an optional data hash, an optional task id and an optional queue name
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/bigwig/push.rb', line 32 def method, data = {}, task_id = nil, queue = :default BigWig::logger.info("Pushing #{method} on to #{queue}") @config = YAML.load(File.open(@options[:config])) BigWig::connect_using @config begin Timeout::timeout(@options[:timeout]) do begin Warren::Queue.publish queue, :method => method, :id => task_id, :data => data rescue Exception => ex BigWig::logger.error("...push failed with #{ex}") exit 1 end end rescue Timeout::Error => te BigWig::logger.error("...push timed out: #{te}") exit 1 end BigWig::logger.info("...bigwig push finished") exit 0 end |