root/trunk/examples/workers/foo_worker.rb

Revision 327, 0.9 kB (checked in by gethema..@gmail.com, 5 months ago)

sync code with git

Line 
1 # Put your code that runs your task inside the do_work method it will be
2 # run automatically in a thread. You have access to all of your rails
3 # models.  You also get logger and results method inside of this class
4 # by default.
5
6 class TimeClient
7   def receive_data(p_data)
8     worker.get_external_data(p_data)
9   end
10
11   def post_init
12     p "***************** : connection completed"
13   end
14 end
15
16 class FooWorker < BackgrounDRb::MetaWorker
17   set_worker_name :foo_worker
18   def create(args = nil)
19     #register_status("Running")
20     add_periodic_timer(10) { foobar }
21     external_connection = nil
22     connect("localhost",11009,TimeClient) { |conn| external_connection = conn }
23   end
24
25   def get_external_data(p_data)
26     cache[some_key] = p_data
27   end
28
29   def foobar
30     cache[some_key] = "Time is now : #{Time.now}"
31   end
32
33   def barbar(data)
34     logger.info "invoking babrbar on #{Time.now} #{data}"
35   end
36
37 end
38
Note: See TracBrowser for help on using the browser.