Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions clients/ruby/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ ticking from your application or an external scheduler — see the
project [Installation](https://github.com/NikolayS/pgque#installation)
section for both paths.

### Event inputs

`Pgque::Event` is an optional value object for carrying a payload and type
together before sending:

```ruby
event = Pgque::Event.new(payload: { "order_id" => 42 }, type: "order.created")
client.send("orders", event)
```

It accepts only `payload:` and `type:`. The receive-side `extra1` through
`extra4` fields are not supported by this producer wrapper; unknown keywords
such as `extra:` raise `ArgumentError`.

### Consumer options

`Consumer.new(..., max_messages: ...)` controls the per-`receive` limit.
Expand Down
5 changes: 2 additions & 3 deletions clients/ruby/lib/pgque/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

module Pgque
class Event
attr_reader :payload, :type, :extra
attr_reader :payload, :type

def initialize(payload:, type: "default", extra: {})
def initialize(payload:, type: "default")
@payload = payload
@type = type
@extra = extra
end
end
end
25 changes: 23 additions & 2 deletions clients/ruby/test/test_send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,33 @@ def test_send_with_explicit_type
end

def test_send_event_object
with_queue do |queue, _consumer, conn|
with_queue do |queue, consumer, conn|
client = Pgque::Client.new(conn)
event = Pgque::Event.new(payload: { "x" => 1 }, type: "custom.t")
payload = { "x" => 1 }
event = Pgque::Event.new(payload: payload, type: "custom.t")
refute_respond_to event, :extra
eid = client.send(queue, event)
assert_kind_of Integer, eid

conn.exec_params("select pgque.force_next_tick($1)", [queue])
conn.exec_params("select pgque.ticker($1)", [queue])
msg = client.receive(queue, consumer, 1).fetch(0)
assert_equal eid, msg.msg_id
assert_equal "custom.t", msg.type
assert_equal payload, msg.payload
client.ack(msg.batch_id)
end
end

def test_event_rejects_extra_keyword_instead_of_silently_dropping_it
error = assert_raises(ArgumentError) do
Pgque::Event.new(
payload: { "x" => 1 },
type: "custom.t",
extra: { "trace_id" => "lost" },
)
end
assert_match(/unknown keyword.*extra/, error.message)
end

def test_send_str_payload_passes_through
Expand Down
Loading