Method: DRbQS::Task#initialize
- Defined in:
- lib/drbqs/task/task.rb
#initialize(obj, method_name, opts = {}, &hook) ⇒ Task
Note:
Changes of obj on a node are not sent to a server. That is, opts[:hook] must not depend on changes of instance variables on a node.
Nodes calculate by obj.method_name(*opts[:args]) and send the result to their server. Then the server executes &hook with a server instance and an object of result. For the communication of a server and nodes we must convert obj to a string by Marshal.dump. If we set both opts[:hook] and &hook then &hook is prior to opts[:hook].
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/drbqs/task/task.rb', line 36 def initialize(obj, method_name, opts = {}, &hook) @obj = obj begin @marshal_obj = Marshal.dump(@obj) rescue raise "Can not dump #{@obj.inspect}." end @method_name = method_name.intern @args = opts[:args] || [] unless Array === @args raise "Arguments of task must be an array." end begin @marshal_args = Marshal.dump(@args) rescue raise "Can not dump #{@args.inspect}." end @note = opts[:note] @hook = hook || opts[:hook] @group = opts[:group] || DRbQS::Task::DEFAULT_GROUP end |