Class: QRPC::Server::Job
- Inherits:
-
Object
- Object
- QRPC::Server::Job
- Includes:
- EM::Deferrable
- Defined in:
- lib/qrpc/server/job.rb
Overview
Queue RPC job.
Constant Summary collapse
- DEFAULT_PRIORITY =
Deprecated.
(since 0.2.0)
Indicates default priority.
QRPC::DEFAULT_PRIORITY
Instance Method Summary collapse
-
#client ⇒ String
Returns client identifier.
-
#initialize(api, job) ⇒ Job
constructor
Constructor.
-
#priority ⇒ Integer
Returns job priority according to request.
-
#process! ⇒ Object
Starts processing.
-
#request ⇒ JsonRpcObjects::Generic::Object
Returns job in request form.
Constructor Details
#initialize(api, job) ⇒ Job
Constructor.
57 58 59 60 |
# File 'lib/qrpc/server/job.rb', line 57 def initialize(api, job) @api = api @job = job end |
Instance Method Details
#client ⇒ String
Returns client identifier.
122 123 124 |
# File 'lib/qrpc/server/job.rb', line 122 def client self.request.qrpc["client"] end |
#priority ⇒ Integer
Returns job priority according to request.
Default priority is 50. You can scale up and down according to your needs in fact without limits.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/qrpc/server/job.rb', line 106 def priority priority = self.request.qrpc["priority"] if priority.nil? priority = QRPC::DEFAULT_PRIORITY else priority = priority.to_i end return priority end |
#process! ⇒ Object
Starts processing.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/qrpc/server/job.rb', line 66 def process! result = nil error = nil request = self.request begin result = @api.send(request.method, *request.params) rescue ::Exception => e error = self.generate_error(request, e) end response = request.class::version.response::create(result, error, :id => request.id) response.qrpc = QRPC::Protocol::QrpcObject::create @job.delete() self.set_deferred_status(:succeeded, response.to_json) end |
#request ⇒ JsonRpcObjects::Generic::Object
Returns job in request form.
89 90 91 92 93 94 95 |
# File 'lib/qrpc/server/job.rb', line 89 def request if @request.nil? @request = JsonRpcObjects::Request::parse(@job.body) end return @request end |