Module: IronConsumer
- Defined in:
- lib/helpers.rb,
lib/iron_consumer.rb,
lib/iron_consumer/version.rb
Overview
hash for user to stuff things to use later.
Constant Summary collapse
- VERSION =
"0.0.5"
- @@connections =
{}
Class Method Summary collapse
Class Method Details
.connections ⇒ Object
5 6 7 |
# File 'lib/helpers.rb', line 5 def self.connections return @@connections end |
.message ⇒ Object
13 14 15 |
# File 'lib/helpers.rb', line 13 def self. @@message end |
.run(config) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/iron_consumer.rb', line 9 def self.run(config) qname = config['workqueue'] # User can have whatever he wants in the usersetup part. # We can put the helpers stuff in a gem that user can optionally use or something. setupfile = config['setup'] || "usersetup.rb" begin load setupfile rescue LoadError => ex p ex puts ex. puts "You need a file called #{setupfile}" exit false end codefile = config['code'] || "usercode.rb" # mongo1 name is defined by user # Other connections would be made here # Iron stuff is setup too: mq = IronMQ::Client.new(config['iron']) # qname defined by user too queue = mq.queue(qname) # This worker kicks off whenever a message gets on a queue (only once, needs alerts) tries = 0 max_tries = 3 sleep_time = 3 while true msg = queue.get if msg == nil # sleep for a short time to see if we can get another one tries += 1 if tries >= max_tries puts "No more messages to process, shutting down." break end sleep sleep_time next end IronConsumer.(msg) begin # USER CODE STUFFED IN HERE begin load codefile rescue LoadError => ex p ex puts "You need a file called #{codefile}." exit false end # USER CODE END # If finished ok, delete message msg.delete rescue Exception => ex puts "Error in user code #{ex} -- #{ex.}" end end end |
.set_message(m) ⇒ Object
9 10 11 |
# File 'lib/helpers.rb', line 9 def self.(m) @@message = m end |