Module: Cuboid::Rest::Server::InstanceHelpers
- Includes:
- Server::InstanceHelpers
- Defined in:
- lib/cuboid/rest/server/instance_helpers.rb
Overview
Sinatra-coupled supplement to ‘Cuboid::Server::InstanceHelpers` —the methods that read `env`, call `handle_error` (a Sinatra helper defined on `Rest::Server`), or prune `session` entries belonging to scheduler-removed instances. Everything that doesn’t need Sinatra stays on the shared module above.
Instance Method Summary collapse
- #instance_for(id, &block) ⇒ Object
-
#spawn(owner_url: env['HTTP_HOST']) ⇒ Object
Forward the request host to the shared spawner so the Agent can log who asked for the instance.
-
#update_from_scheduler ⇒ Object
Adds Sinatra-session cleanup for IDs the scheduler has dropped.
Methods included from Server::InstanceHelpers
agent, #agent, #agents, connect_to_agent, #connect_to_agent, connect_to_instance, #connect_to_instance, #connect_to_scheduler, #exists?, instances, #instances, #scheduler, spawn, #unplug_agent
Instance Method Details
#instance_for(id, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cuboid/rest/server/instance_helpers.rb', line 35 def instance_for( id, &block ) cleanup = proc do instances.delete( id ).close session.delete id end handle_error cleanup do block.call instances[id] end end |
#spawn(owner_url: env['HTTP_HOST']) ⇒ Object
Forward the request host to the shared spawner so the Agent can log who asked for the instance.
18 19 20 |
# File 'lib/cuboid/rest/server/instance_helpers.rb', line 18 def spawn( owner_url: env['HTTP_HOST'] ) super end |
#update_from_scheduler ⇒ Object
Adds Sinatra-session cleanup for IDs the scheduler has dropped. The shared ‘update_from_scheduler` already removes them from the instance map; this override prunes the matching session keys so a second request from the same browser doesn’t try to reach a dead instance.
27 28 29 30 31 32 33 |
# File 'lib/cuboid/rest/server/instance_helpers.rb', line 27 def update_from_scheduler return if !scheduler pruned = scheduler.failed.keys | scheduler.completed.keys super pruned.each { |id| session.delete id } end |