Class: KermitPFC
- Inherits:
-
Object
- Object
- KermitPFC
- Defined in:
- lib/kermitpfc.rb
Overview
Masterclass that adapts the rakefile into a class to use the commander gem
Instance Method Summary collapse
-
#cleaning_the_house ⇒ Object
Deletes the db keys previously used.
-
#initialize ⇒ KermitPFC
constructor
Load the config file.
-
#initialize_websocket_server ⇒ Object
Starts the WebSocket Server.
-
#random_adapter(stream = 1) ⇒ Object
Starts the Random Adapter.
-
#random_converter ⇒ Object
Starts the Random Converter.
-
#twitter_adapter(stream) ⇒ Object
Starts the Twitter Adapter.
-
#twitter_converter ⇒ Object
Starts the Twitter Converter.
Constructor Details
#initialize ⇒ KermitPFC
Load the config file
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 |
# File 'lib/kermitpfc.rb', line 18 def initialize begin cleaning_the_house puts 'pooling' pool = [] pool << Thread.new { initialize_websocket_server } puts 'websocket started' for i in 1..Logging::Settings.twitter.streams puts "adding twitter adapter ##{i}" pool << Thread.new { twitter_adapter i } sleep 1 end puts 'twitter adapters added' if Logging::Settings.rpg pool << Thread.new { random_adapter } puts 'random adapter added' pool << Thread.new { random_converter } puts 'random converter added' end pool << Thread.new { twitter_converter } puts 'twitter converter added' pool.each do |thread| thread.join end rescue Exception => e Logging::logger.error(e) pool.each do |thread| Thread.kill(thread) end end end |
Instance Method Details
#cleaning_the_house ⇒ Object
Deletes the db keys previously used
72 73 74 75 76 77 |
# File 'lib/kermitpfc.rb', line 72 def cleaning_the_house dao = DAO.new dao.clean end |
#initialize_websocket_server ⇒ Object
Starts the WebSocket Server
80 81 82 83 84 85 |
# File 'lib/kermitpfc.rb', line 80 def initialize_websocket_server ws = WebSocketServer.new ws.start end |
#random_adapter(stream = 1) ⇒ Object
Starts the Random Adapter
100 101 102 103 104 105 |
# File 'lib/kermitpfc.rb', line 100 def random_adapter stream=1 ra = RandomAdapter.new ra.connect_stream stream end |
#random_converter ⇒ Object
Starts the Random Converter
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/kermitpfc.rb', line 137 def random_converter dao = DAO.new 'rpg' while true status = dao.get_status puts 'Status retrieved' while status != nil rc = RandomConverter.new usmf = rc.to_usmf status dao.publish usmf.to_hash.to_json puts 'Published' status = dao.get_status end puts 'All the statuses were been sent' sleep 2 end end |
#twitter_adapter(stream) ⇒ Object
Starts the Twitter Adapter
90 91 92 93 94 95 |
# File 'lib/kermitpfc.rb', line 90 def twitter_adapter stream ta = TwitterAdapter.new ta.connect_stream stream end |
#twitter_converter ⇒ Object
Starts the Twitter Converter
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/kermitpfc.rb', line 108 def twitter_converter dao = DAO.new 'twitter' while true status = dao.get_status puts 'Status retrieved' while status != nil tc = TwitterConverter.new usmf = tc.to_usmf status dao.publish usmf.to_hash.to_json puts 'Published' status = dao.get_status end puts 'All the statuses were been sent' sleep 2 end end |