Skip to content

Commit d986d5f

Browse files
authored
Merge pull request #18 from bigcommerce/call-opts
Add the ability for call options to the client, which enables deadline setting
2 parents 4867bfa + 9969825 commit d986d5f

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Changelog for the gruf gem. This includes internal history before the gem was made.
22

3+
h3. 1.1.0
4+
5+
- Add the ability for call options to the client, which enables deadline setting
6+
37
h3. 1.0.0
48

59
- Bump gRPC to 1.4

lib/gruf/client.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ def initialize(service:, options: {})
4747
##
4848
# Call the client's method with given params
4949
#
50-
def call(request_method, params = {}, metadata = {})
50+
def call(request_method, params = {}, metadata = {}, opts = {})
5151
req = request_object(request_method, params)
5252
md = build_metadata(metadata)
5353
call_sig = call_signature(request_method)
5454

5555
raise NotImplementedError, "The method #{request_method} has not been implemented in this service." unless call_sig
5656

57-
execute(call_sig, req, md)
57+
execute(call_sig, req, md, opts)
5858
rescue GRPC::BadStatus => e
5959
emk = Gruf.error_metadata_key.to_s
6060
raise Gruf::Client::Error, error_deserializer_class.new(e.metadata[emk]).deserialize if e.respond_to?(:metadata) && e.metadata.key?(emk)
@@ -68,9 +68,11 @@ def call(request_method, params = {}, metadata = {})
6868
# @param [Object] req
6969
# @param [Hash] md
7070
#
71-
def execute(call_sig, req, md)
71+
def execute(call_sig, req, md, opts)
7272
timed = Timer.time do
73-
send(call_sig, req, return_op: true, metadata: md)
73+
opts[:return_op] = true
74+
opts[:metadata] = md
75+
send(call_sig, req, opts)
7476
end
7577
Gruf::Response.new(timed.result, timed.time)
7678
end

lib/gruf/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1616
#
1717
module Gruf
18-
VERSION = '1.0.0'.freeze
18+
VERSION = '1.1.0'.freeze
1919
end

spec/gruf/client_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
describe '.call' do
4747
let(:metadata) { { foo: 'bar' } }
4848
let(:params) { { id: 1 } }
49+
let(:opts) { {} }
4950
let(:op) { build_operation(metadata: metadata) }
50-
subject { client.call(method_name, params, metadata) }
51+
subject { client.call(method_name, params, metadata, opts) }
5152

5253
context 'if the call is successful' do
5354
let(:req) { Rpc::GetThingRequest.new(params) }
@@ -57,6 +58,16 @@
5758
expect(client).to receive(:get_thing).with(req, return_op: true, metadata: metadata).and_return(op)
5859
expect(subject).to be_truthy
5960
end
61+
62+
context 'with a deadline' do
63+
let(:deadline) { Time.now + 42 }
64+
let(:opts) { { deadline: deadline } }
65+
66+
it 'should pass the deadline into the call' do
67+
expect(client).to receive(:get_thing).with(req, return_op: true, metadata: metadata, deadline: deadline).and_return(op)
68+
expect(subject).to be_truthy
69+
end
70+
end
6071
end
6172

6273
context 'if a GRPC::BadStatus is raised' do

0 commit comments

Comments
 (0)