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.
83 84 85 86 87 88 89 |
# File 'lib/qrpc/client/job.rb', line 83 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.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/qrpc/client/job.rb', line 129 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.
96 97 98 99 100 101 102 |
# File 'lib/qrpc/client/job.rb', line 96 def id if @id.nil? @id = UUID.generate(:compact).to_sym end return @id end |
#notification? ⇒ Boolean
Indicates message is notification. So callback isn’t set and it doesn’t expect any result.
120 121 122 |
# File 'lib/qrpc/client/job.rb', line 120 def notification? @callback.nil? end |