Class: Insika::Commands::DeleteAgent
- Inherits:
-
Object
- Object
- Insika::Commands::DeleteAgent
- Defined in:
- lib/insika/commands/delete_agent.rb
Overview
Control command: removes an agent. -> the removed AgentProfile (so the transport can confirm what disappeared). Turns ALREADY in progress that captured the profile keep going until they finish (the ProfileSource only affects new dispatches).
Instance Method Summary collapse
- #call(command) ⇒ Object
-
#initialize(profile_source:, event_stream:) ⇒ DeleteAgent
constructor
A new instance of DeleteAgent.
Constructor Details
#initialize(profile_source:, event_stream:) ⇒ DeleteAgent
Returns a new instance of DeleteAgent.
12 13 14 15 |
# File 'lib/insika/commands/delete_agent.rb', line 12 def initialize(profile_source:, event_stream:) @profile_source = profile_source @event_stream = event_stream end |
Instance Method Details
#call(command) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/insika/commands/delete_agent.rb', line 17 def call(command) id = AgentPayload.presence(AgentPayload.symbolize(command.payload)[:id]) raise Insika::ValidationError, "id is required" if id.nil? removed = @profile_source.fetch(id) || (raise Insika::NotFoundError, "agent '#{id}' not found") @profile_source.delete(id) @event_stream.emit(Insika::Event.new( type: :agent_deleted, data: { agent_id: id }, meta: { at: Time.now.utc.iso8601 } )) removed end |