Permalink
Browse files

update example worker

  • Loading branch information...
1 parent 7abc827 commit ca7d4cb7ff1b6c283601683adf3fce18f94a75a4 @gnufied committed Jul 16, 2008
Showing with 21 additions and 15 deletions.
  1. +9 −5 examples/foo_controller.rb
  2. +2 −2 examples/workers/foo_worker.rb
  3. +10 −8 examples/workers/rss_worker.rb
@@ -8,31 +8,35 @@ def mobile_action
end
def start_worker
- MiddleMan.new_worker(:worker => :error_worker, :job_key => :hello_world,:data => "wow_man",:schedule => { :hello_world => { :trigger_args => "*/5 * * * * * *",:data => "hello_world" }})
+ MiddleMan.new_worker(:worker => :error_worker, :worker_key => :hello_world,:data => "wow_man")
render :text => "worker starterd"
end
def stop_worker
- MiddleMan.delete_worker(:worker => :error_worker, :job_key => :hello_world)
+ MiddleMan.worker(:error_worker,:hello_world).delete
render :text => "worker deleted"
end
def invoke_worker_method
- worker_response = MiddleMan.send_request(:worker => :world_worker, :worker_method => :hello_world)
+ worker_response = MiddleMan.worker(:hello_worker).say_hello(:arg => data)
render :text => worker_response
end
def renew
- MiddleMan.ask_work(:worker => :renewal_worker, :worker_method => :load_policies)
+ MiddleMan.worker(:hello_worker).async_load_policy(:arg => current_user.id)
render :text => "method invoked"
end
- def ask_status
+ def query_all_workers
t_response = MiddleMan.query_all_workers
running_workers = t_response.map { |key,value| "#{key} = #{value}"}.join(',')
render :text => running_workers
end
+ def ask_result
+ t_result = MiddleMan.worker(:hello_worker).ask_result(cache_key)
+ end
+
private
def choose_layout
if action_name == 'mobile_action'
@@ -23,11 +23,11 @@ def create(args = nil)
end
def get_external_data(p_data)
- register_status(p_data)
+ cache[some_key] = p_data
end
def foobar
- register_status("Hello #{Time.now}")
+ cache[some_key] = "Time is now : #{Time.now}"
end
def barbar(data)
@@ -9,15 +9,17 @@ def create(args = nil)
# method would fetch supplied urls in a thread
def fetch_url(url)
puts "fetching url #{url}"
- thread_pool.defer(url) do |url|
- begin
- data = Net::HTTP.get('www.example.com','/')
- File.open("#{RAILS_ROOT}/log/pages.txt","w") do |fl|
- fl.puts(data)
- end
- rescue
- logger.info "Error downloading page"
+ thread_pool.defer(:scrap_things,url)
+ end
+
+ def scrap_things url
+ begin
+ data = Net::HTTP.get(url,"/")
+ File.open("#{RAILS_ROOT}/log/pages.txt","w") do |fl|
+ fl.puts(data)
end
+ rescue
+ logger.info "Error downloading page"
end
end
end

0 comments on commit ca7d4cb

Please sign in to comment.