Changeset 196
- Timestamp:
- 11/13/07 20:48:32 (1 year ago)
- Files:
-
- branches/version10/README (modified) (12 diffs)
- branches/version10/lib/backgroundrb.rb (modified) (1 diff)
- branches/version10/script/backgroundrb (modified) (1 diff)
- branches/version10/server/master_worker.rb (modified) (1 diff)
- branches/version10/server/meta_worker.rb (modified) (1 diff)
- branches/version10/server/trigger.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/version10/README
r195 r196 10 10 Rails. So any Ruby program or framework can use it. 11 11 12 Copyright (c) 2006 Ezra Zygmuntowicz,skaar[at]waste[dot]org, 12 Copyright (c) 2006 Ezra Zygmuntowicz,skaar[at]waste[dot]org, 13 13 Copyright (c) 2007 Hemant Kumar (mail[at]gnufied[dot]org) 14 14 … … 33 33 piston import http://svn.devjavu.com/backgroundrb/branches/version10/ backgroundrb 34 34 35 === Configuration 35 === Configuration 36 36 Use rake task for initial configuration: 37 37 … … 55 55 | :start: <%= Time.now + 5.seconds %> 56 56 | :end: <%= Time.now + 10.minutes %> 57 | :repeat_interval: 1.minute57 | :repeat_interval: <%= 1.minute %> 58 58 59 59 * Plain config … … 69 69 invocation of a method should be more than the time thats actually required to execute the method. 70 70 If a method takes longer time than the time window specified, your method invocations would lag 71 perpetually. 71 perpetually. 72 72 - Normal Scheduler 73 73 You can use second form of scheduling as shown in config file. … … 75 75 A third and very basic form of scheduling that you can use is, "add_periodic_timer" method. You can call 76 76 method from anywhere in your worker. 77 77 78 78 def create 79 79 add_periodic_timer(5) { say_hello } 80 80 end 81 81 82 82 Above snippet would register the proc for periodic execution at every 5 seconds. 83 83 84 84 === Code 85 85 Install the plugin, and run setup task. Create a worker, using worker generator. 86 86 87 87 ./script/generatr worker bar 88 88 … … 96 96 puts "starting a bar worker" 97 97 end 98 98 99 99 def process_request(p_data) 100 100 user_input = p_data[:data] … … 136 136 137 137 === Legacy and deprecated stuff 138 138 139 139 Although, You need to wrap your head a bit for understanding "evented" model of network programming a bit, 140 140 but it gets easier once you get the hang of it. Much of the older stuff is deprecated. Here is a brief list: … … 144 144 I don't know if many people used this feature, and is probably easy to implement back. 145 145 - Threads: find .|grep 'Thread' , gone 146 - Passing of arguments from configuration file. 146 - Passing of arguments from configuration file. 147 147 Again, I am not sure many people used it either, if you are passing arguments to periodic 148 148 methods from configuration files, you may as well hardcode that argument in worker itself. … … 162 162 end 163 163 end 164 164 165 165 And using MiddleMan proxy, you can keep queering status of your progress bar: 166 167 MiddleMan.ask_status(:worker => :progress_worker) 166 167 MiddleMan.ask_status(:worker => :progress_worker) 168 168 169 169 I would welcome, anyone who contributes more examples back. You can even use callbacks … … 173 173 * Rock solid stable. 174 174 * Master is using a hash for storing status of each worker. I am thinking of adding something like this: 175 175 176 176 #backgroundrb.yml 177 177 status_storage: 178 storage: db 178 storage: db 179 179 database: worker_status 180 180 * Each worker comes with Event loop of its own and can potentially do lots of fancy stuff. Two noteworthy methods are: … … 182 182 connect(ip,port,Handler) 183 183 start_worker(ip,port,Handler) 184 184 185 185 If you are familiar with EventMachine or Twisted style of network programming, above methods allow you to 186 186 start tcp servers inside your workers or lets you connect to external tcp servers. For Each accepted client or 187 187 connected socket a instance of Handler class would be created and integrated with main event loop. 188 188 This can be used for worker to worker communication between backgroundrb servers running on two machines. 189 189 190 190 You are encouraged to look into framework directory, and see the code that implements all this stuff.Guts of 191 191 new bdrb is based on this library, which would be released soon as separately. … … 196 196 - http://backgroundrb.rubyforge.org (rdoc) 197 197 198 == DISCLAIMER 198 == DISCLAIMER 199 199 200 200 New Version of BackgrounDrb is uses processes and evented model of programming. branches/version10/lib/backgroundrb.rb
r185 r196 11 11 include Packet::NbioHelper 12 12 def self.init 13 @@config = YAML.load(File.open("#{BACKGROUNDRB_ROOT}/config/backgroundrb.yml")) 13 # @@config = YAML.load(File.open("#{BACKGROUNDRB_ROOT}/config/backgroundrb.yml")) 14 @@config = YAML.load(ERB.new(IO.read("#{BACKGROUNDRB_ROOT}/config/backgroundrb.yml")).result) 14 15 @@server_ip = @@config[:backgroundrb][:ip] 15 16 @@server_port = @@config[:backgroundrb][:port] branches/version10/script/backgroundrb
r188 r196 14 14 else 15 15 path = "#{RAILS_HOME}/log/backgroundrb.pid" 16 log_file = File.open("#{RAILS_HOME}/log/backgroundrb_server.log","w+") 16 17 op = File.open(path, "w") 17 18 op.write(Process.pid().to_s) 18 19 op.close 19 [STDIN, STDOUT, STDERR].each {|desc| desc.reopen( '/dev/null', "r+")}20 [STDIN, STDOUT, STDERR].each {|desc| desc.reopen(log_file)} 20 21 MasterProxy.new() 21 22 end branches/version10/server/master_worker.rb
r185 r196 66 66 class MasterProxy 67 67 def initialize 68 config_file = YAML.load(File.open("#{RAILS_HOME}/config/backgroundrb.yml")) 68 #config_file = YAML.load(File.open("#{RAILS_HOME}/config/backgroundrb.yml")) 69 config_file = YAML.load(ERB.new(IO.read("#{RAILS_HOME}/config/backgroundrb.yml")).result) 69 70 Packet::Reactor.run do |t_reactor| 70 71 t_reactor.start_server(config_file[:backgroundrb][:ip],config_file[:backgroundrb][:port],MasterWorker) branches/version10/server/meta_worker.rb
r191 r196 5 5 6 6 def worker_init 7 @config_file = YAML.load( File.open("#{RAILS_HOME}/config/backgroundrb.yml"))7 @config_file = YAML.load(ERB.new(IO.read("#{RAILS_HOME}/config/backgroundrb.yml")).result) 8 8 if @config_file[:schedules] 9 9 @my_schedule = @config_file[:schedules][worker_name.to_sym] branches/version10/server/trigger.rb
r185 r196 5 5 6 6 def initialize(opts={}) 7 @start_time = opts[:start]8 @end_time = opts[:end]9 @repeat_interval = opts[:repeat_interval] 7 @start_time = Time.parse(opts[:start]) 8 @end_time = Time.parse(opts[:end]) 9 @repeat_interval = opts[:repeat_interval].to_i 10 10 end 11 11
