Change segment order for batch resource topics
parent
fbdebb1b76
commit
8b81317087
|
@ -8,7 +8,7 @@ module Resources
|
|||
#
|
||||
# ["bot", "device_3", "resources_v0", "destroy", "Sequence", "2", "xyz"]
|
||||
segments = delivery_info.routing_key.split(".")
|
||||
_, device_name, _, action, resource, resource_id, uuid = segments
|
||||
_, device_name, _, action, resource, uuid, resource_id = segments
|
||||
run!(device_name: device_name,
|
||||
action: action,
|
||||
resource: resource,
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
module Resources
|
||||
class Service
|
||||
MQTT_CHAN = "from_api"
|
||||
CHANNEL_TPL =
|
||||
"bot.device_%{device_id}.resources_v0.%{action}.%{klass}.%{uuid}.%{id}"
|
||||
INDEX_OF_USERNAME = 1
|
||||
INDEX_OF_OP = 3
|
||||
INDEX_OF_KIND = 4
|
||||
INDEX_OF_UUID = 5
|
||||
INDEX_OF_ID = 6
|
||||
|
||||
class Service
|
||||
|
||||
def self.ok(uuid)
|
||||
{ kind: "rpc_ok", args: { label: uuid } }.to_json
|
||||
end
|
||||
|
@ -21,8 +30,8 @@ module Resources
|
|||
rescue Mutations::ValidationException => q
|
||||
Rollbar.error(q)
|
||||
raw_chan = delivery_info&.routing_key&.split(".") || []
|
||||
id = raw_chan[1]&.gsub("device_", "")&.to_i
|
||||
uuid = (raw_chan.last || "NONE")
|
||||
id = raw_chan[INDEX_OF_USERNAME]&.gsub("device_", "")&.to_i
|
||||
uuid = raw_chan[INDEX_OF_UUID] || "NONE"
|
||||
Transport.current.amqp_send(rpc_err(uuid, q), id, MQTT_CHAN) if id
|
||||
nil
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@ Not all resources support the experimental resource API.
|
|||
Send an MQTT message in the format of:
|
||||
|
||||
```
|
||||
bot/device_<id>/resources_v0/<action>/<resource type>/<resource_id or 0>/<Transaction UUID>
|
||||
bot/device_<id>/resources_v0/<action>/<resource type>/<Transaction UUID>/<resource_id or 0>
|
||||
```
|
||||
|
||||
Example 1-1:
|
||||
|
|
|
@ -2,8 +2,6 @@ require "spec_helper"
|
|||
|
||||
describe Resources::PreProcessor do
|
||||
DeliveryInfoShim = Struct.new(:routing_key)
|
||||
CHANNEL_TPL =
|
||||
"bot.device_%{device_id}.resources_v0.%{action}.%{klass}.%{id}.%{uuid}"
|
||||
|
||||
let(:pb) { FactoryBot.create(:pin_binding) }
|
||||
|
||||
|
@ -17,7 +15,7 @@ describe Resources::PreProcessor do
|
|||
|
||||
let(:preprocessed) do
|
||||
body = {}.to_json
|
||||
chan = CHANNEL_TPL % props
|
||||
chan = Resources::CHANNEL_TPL % props
|
||||
Resources::PreProcessor.from_amqp(DeliveryInfoShim.new(chan), body)
|
||||
end
|
||||
|
||||
|
@ -32,7 +30,7 @@ describe Resources::PreProcessor do
|
|||
|
||||
it "handles bad JSON" do
|
||||
body = "}{"
|
||||
chan = CHANNEL_TPL % props
|
||||
chan = Resources::CHANNEL_TPL % props
|
||||
expect do
|
||||
Resources::PreProcessor.from_amqp(DeliveryInfoShim.new(chan), body)
|
||||
end.to raise_error(Mutations::ValidationException, "body must be a JSON object")
|
||||
|
@ -41,7 +39,7 @@ describe Resources::PreProcessor do
|
|||
describe Resources::Service do
|
||||
it "handles syntax errors using step1" do
|
||||
body = "[]"
|
||||
chan = CHANNEL_TPL % props
|
||||
chan = Resources::CHANNEL_TPL % props
|
||||
shim = DeliveryInfoShim.new(chan)
|
||||
Resources::Service.process(shim, body)
|
||||
result = Transport.current.connection
|
||||
|
@ -88,7 +86,7 @@ describe Resources::PreProcessor do
|
|||
|
||||
it "processes resources" do
|
||||
body = {}.to_json
|
||||
chan = CHANNEL_TPL % props
|
||||
chan = Resources::CHANNEL_TPL % props
|
||||
before = PinBinding.count
|
||||
result = Resources::Service.process(DeliveryInfoShim.new(chan), body)
|
||||
expect(PinBinding.count).to be < before
|
||||
|
|
Loading…
Reference in New Issue