Class: QRPC::Client::Job
- Inherits:
-
Object
- Object
- QRPC::Client::Job
- Defined in:
- lib/qrpc/client/job.rb
Overview
Queue RPC client job.
Instance Method Summary collapse
-
#assign_result(result) ⇒ Object
Assigns job result and subsequently calls callback.
-
#id ⇒ Symbol
Returns job ID.
-
#initialize(client_id, method, arguments = [ ], priority = QRPC::DEFAULT_PRIORITY, &callback) ⇒ Job
constructor
Constructor.
-
#notification? ⇒ Boolean
Indicates message is notification.
-
#to_json ⇒ String
Converts job to JSON.
Constructor Details
#initialize(client_id, method, arguments = [ ], priority = QRPC::DEFAULT_PRIORITY, &callback) ⇒ Job
Constructor.
78 79 80 81 82 83 84 |
# File 'lib/qrpc/client/job.rb', line 78 def initialize(client_id, method, arguments = [ ], priority = QRPC::DEFAULT_PRIORITY, &callback) @client_id = client_id @method = method @arguments = arguments @callback = callback @priority = priority end |
Instance Method Details
#assign_result(result) ⇒ Object
Assigns job result and subsequently calls callback.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/qrpc/client/job.rb', line 124 def assign_result(result) if not result.error? @result = result.result else =begin STDERR.write(">>> Exception while call ID: " << self.id.to_s << "\n") =end exception = QRPC::Client::Exception::get(result.error) =begin STDERR.write exception.class.name.dup << ": " << exception.message << "\n" exception.backtrace.each do |i| STDERR.write " from " << i << "\n" end =end raise exception end if not @callback.nil? @callback.call(@result) end end |
#id ⇒ Symbol
Returns job ID.
91 92 93 94 95 96 97 |
# File 'lib/qrpc/client/job.rb', line 91 def id if @id.nil? @id = UUID.generate.to_sym end return @id end |
#notification? ⇒ Boolean
Indicates message is notification. So callback isn’t set and it doesn’t expect any result.
115 116 117 |
# File 'lib/qrpc/client/job.rb', line 115 def notification? @callback.nil? end |