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, generator = QRPC::default_generator, protocol = QRPC::default_protocol, &callback) ⇒ Job
constructor
Constructor.
-
#notification? ⇒ Boolean
Indicates message is notification.
-
#serialize ⇒ Object
Serializes job using serializer.
-
#to_json ⇒ String
deprecated
Deprecated.
(since 0.4.0) Use
#serialize
.
Constructor Details
#initialize(client_id, method, arguments = [ ], priority = QRPC::DEFAULT_PRIORITY, generator = QRPC::default_generator, protocol = QRPC::default_protocol, &callback) ⇒ Job
Constructor.
99 100 101 102 103 104 105 106 107 |
# File 'lib/qrpc/client/job.rb', line 99 def initialize(client_id, method, arguments = [ ], priority = QRPC::DEFAULT_PRIORITY, generator = QRPC::default_generator, protocol = QRPC::default_protocol, &callback) @client_id = client_id @method = method @arguments = arguments @callback = callback @priority = priority @protocol = protocol @generator = generator end |
Instance Method Details
#assign_result(result) ⇒ Object
Assigns job result and subsequently calls callback.
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/qrpc/client/job.rb', line 170 def assign_result(result) if not result.error? @result = result.result else exception = result.error raise exception end if not @callback.nil? @callback.call(@result) end end |
#id ⇒ Symbol
Returns job ID.
114 115 116 117 118 119 120 |
# File 'lib/qrpc/client/job.rb', line 114 def id if @id.nil? @id = @generator.generate(self) else @id end end |
#notification? ⇒ Boolean
Indicates message is notification. So callback isn’t set and it doesn’t expect any result.
161 162 163 |
# File 'lib/qrpc/client/job.rb', line 161 def notification? @callback.nil? end |
#serialize ⇒ Object
Serializes job using serializer.
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/qrpc/client/job.rb', line 141 def serialize = { :client_id => @client_id, :id => @id, :method => @method, :arguments => @arguments, :priority => @priority, :notification => self.notification? } @protocol.request::new().serialize end |
#to_json ⇒ String
Deprecated.
(since 0.4.0) Use #serialize
.
Converts job to JSON.
130 131 132 |
# File 'lib/qrpc/client/job.rb', line 130 def to_json JsonRpc::Request::create(@client_id, @id, @method, @arguments, @priority).to_json end |