Changeset 196

Show
Ignore:
Timestamp:
11/13/07 20:48:32 (1 year ago)
Author:
gethema..@gmail.com
Message:

fix some minor issues

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/version10/README

    r195 r196  
    1010Rails. So any Ruby program or framework can use it. 
    1111 
    12 Copyright (c) 2006 Ezra Zygmuntowicz,skaar[at]waste[dot]org,  
     12Copyright (c) 2006 Ezra Zygmuntowicz,skaar[at]waste[dot]org, 
    1313Copyright (c) 2007 Hemant Kumar (mail[at]gnufied[dot]org) 
    1414 
     
    3333  piston import http://svn.devjavu.com/backgroundrb/branches/version10/ backgroundrb 
    3434 
    35 === Configuration  
     35=== Configuration 
    3636  Use rake task for initial configuration: 
    3737 
     
    5555  |     :start: <%= Time.now + 5.seconds %> 
    5656  |     :end: <%= Time.now + 10.minutes %> 
    57   |     :repeat_interval: 1.minute 
     57  |     :repeat_interval: <%= 1.minute %> 
    5858 
    5959* Plain config 
     
    6969    invocation of a method should be more than the time thats actually required to execute the method. 
    7070    If a method takes longer time than the time window specified, your method invocations would lag 
    71     perpetually.  
     71    perpetually. 
    7272  - Normal Scheduler 
    7373    You can use second form of scheduling as shown in config file. 
     
    7575    A third and very basic form of scheduling that you can use is, "add_periodic_timer" method. You can call 
    7676    method from anywhere in your worker. 
    77             
     77 
    7878           def create 
    7979             add_periodic_timer(5) { say_hello } 
    8080           end 
    81    
     81 
    8282    Above snippet would register the proc for periodic execution at every 5 seconds. 
    8383 
    8484=== Code 
    8585  Install the plugin, and run setup task. Create a worker, using worker generator. 
    86            
     86 
    8787          ./script/generatr worker bar 
    8888 
     
    9696      puts "starting a bar worker" 
    9797    end 
    98    
     98 
    9999    def process_request(p_data) 
    100100      user_input = p_data[:data] 
     
    136136 
    137137=== Legacy and deprecated stuff 
    138     
     138 
    139139   Although, You need to wrap your head a bit for understanding "evented" model of network programming a bit, 
    140140   but it gets easier once you get the hang of it. Much of the older stuff is deprecated. Here is a brief list: 
     
    144144     I don't know if many people used this feature, and is probably easy to implement back. 
    145145   - Threads: find .|grep 'Thread' , gone 
    146    - Passing of arguments from configuration file.  
     146   - Passing of arguments from configuration file. 
    147147     Again, I am not sure many people used it either, if you are passing arguments to periodic 
    148148     methods from configuration files, you may as well hardcode that argument in worker itself. 
     
    162162       end 
    163163     end 
    164       
     164 
    165165   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) 
    168168 
    169169   I would welcome, anyone who contributes more examples back. You can even use callbacks 
     
    173173  * Rock solid stable. 
    174174  * Master is using a hash for storing status of each worker. I am thinking of adding something like this: 
    175      
     175 
    176176        #backgroundrb.yml 
    177177        status_storage: 
    178           storage: db  
     178          storage: db 
    179179          database: worker_status 
    180180  * Each worker comes with Event loop of its own and can potentially do lots of fancy stuff. Two noteworthy methods are: 
     
    182182         connect(ip,port,Handler) 
    183183         start_worker(ip,port,Handler) 
    184          
     184 
    185185    If you are familiar with EventMachine or Twisted style of network programming, above methods allow you to 
    186186    start tcp servers inside your workers or lets you connect to external tcp servers. For Each accepted client or 
    187187    connected socket a instance of Handler class would be created and integrated with main event loop. 
    188188    This can be used for worker to worker communication between backgroundrb servers running on two machines. 
    189      
     189 
    190190    You are encouraged to look into framework directory, and see the code that implements all this stuff.Guts of 
    191191    new bdrb is based on this library, which would be released soon as separately. 
     
    196196- http://backgroundrb.rubyforge.org (rdoc) 
    197197 
    198 == DISCLAIMER  
     198== DISCLAIMER 
    199199 
    200200New Version of BackgrounDrb is uses processes and evented model of programming. 
  • branches/version10/lib/backgroundrb.rb

    r185 r196  
    1111  include Packet::NbioHelper 
    1212  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) 
    1415    @@server_ip = @@config[:backgroundrb][:ip] 
    1516    @@server_port = @@config[:backgroundrb][:port] 
  • branches/version10/script/backgroundrb

    r188 r196  
    1414  else 
    1515    path = "#{RAILS_HOME}/log/backgroundrb.pid" 
     16    log_file = File.open("#{RAILS_HOME}/log/backgroundrb_server.log","w+") 
    1617    op = File.open(path, "w") 
    1718    op.write(Process.pid().to_s) 
    1819    op.close 
    19     [STDIN, STDOUT, STDERR].each {|desc| desc.reopen('/dev/null', "r+")} 
     20    [STDIN, STDOUT, STDERR].each {|desc| desc.reopen(log_file)} 
    2021    MasterProxy.new() 
    2122  end 
  • branches/version10/server/master_worker.rb

    r185 r196  
    6666class MasterProxy 
    6767  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) 
    6970    Packet::Reactor.run do |t_reactor| 
    7071      t_reactor.start_server(config_file[:backgroundrb][:ip],config_file[:backgroundrb][:port],MasterWorker) 
  • branches/version10/server/meta_worker.rb

    r191 r196  
    55 
    66    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
    88      if @config_file[:schedules] 
    99        @my_schedule = @config_file[:schedules][worker_name.to_sym] 
  • branches/version10/server/trigger.rb

    r185 r196  
    55 
    66    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 
    1010    end 
    1111